ash

decompiled_code:
double __fastcall ash(double a1, double a2)
{
double v2; // rbp
double v3; // xmm0_8
double v5; // [rsp+0h] [rbp-18h]

v5 = a1;
v2 = 1.0;
if ( a1 < 0.0 )
{
v5 = -a1;
v2 = -1.0;
}
v3 = sqr(v5 * v5 + 1.0, a2);
return ln(v3 + v5, a2) * v2;
}

canonical_decompiled_code:
double __fastcall func13(double a1, double a2)
{
double v2; // rbp
double v3; // xmm0_8
double v5; // [rsp+0h] [rbp-18h]

v5 = a1;
v2 = 1.0;
if ( a1 < 0.0 )
{
v5 = -a1;
v2 = -1.0;
}
v3 = func9(v5 * v5 + 1.0, a2);
return func10(v3 + v5, a2) * v2;
}

original_code:
double ash (double x, double eps) {
 double c = 1;
 if (x<0) { c=-1.0; x=-x; }
 return c* ln(x+sqr(1+x*x,eps),eps);
}

canonical_original_code:
double ash(double x, double eps) {
 double c = 1;
 if (x<0) { c=-1.0; x=-x; }
 return c* ln(x+sqr(1+x*x,eps),eps);
}


accuracy

repo: kusha/iterations-counting

decompiled_code:
double __fastcall accuracy(int a1)
{
int v1; // edi
int v2; // eax
double result; // xmm0_8

if ( a1 < 0 )
return 1.0;
v1 = a1 + 1;
v2 = 0;
result = 1.0;
do
{
result = result / 10.0;
++v2;
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
double __fastcall func14(int a1)
{
int v1; // edi
int v2; // eax
double result; // xmm0_8

if ( a1 < 0 )
return 1.0;
v1 = a1 + 1;
v2 = 0;
result = 1.0;
do
{
result = result / 10.0;
++v2;
}
while ( v2 != v1 );
return result;
}

original_code:
double accuracy (int sigdig) {
 double acc = 1;
 int i;
 for (i=0; i<=sigdig; ++i) {
  acc = acc/10;
 }
 return acc;
}

canonical_original_code:
double accuracy(int sigdig) {
 double acc = 1;
 int i;
 for (i=0; i<=sigdig; ++i) {
  acc = acc/10;
 }
 return acc;
}

variable_types: sigdig int

variable_types: acc double

variable_types: i int

return_type: double


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // r14
const char *v4; // rbx
char v5; // r13
char v6; // r12
char v7; // bl
const char *v8; // rdi
int v9; // er15
const char *v10; // rdi
double v11; // rbp
int v13; // eax
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // [rsp+8h] [rbp-40h]

v4 = argv[1];
if ( !v4 )
goto LABEL_12;
if ( strcmp(v4, HELP0) && strcmp(v4, HELP1) )
{
if ( !strcmp(v4, ARG_POW) )
{
v5 = 0;
v6 = 0;
v7 = 1;
goto LABEL_6;
}
if ( !strcmp(v4, ARG_ARCTG) )
{
v5 = 0;
v6 = 1;
v7 = 0;
goto LABEL_6;
}
if ( !strcmp(v4, ARG_ARSINH) )
{
v5 = 1;
v6 = 0;
v7 = 0;
goto LABEL_6;
}
LABEL_12:
fputs(ERRMSG0, stderr);
return 1;
}
if ( (unsigned int)print_help() )
return 0;
v5 = 0;
v6 = 0;
v7 = 0;
LABEL_6:
v8 = argv[2];
if ( !v8 || (v9 = atoi(v8), v9 < 0) )
{
fputs(ERRMSG2, stderr);
return 1;
}
if ( v7 )
{
v10 = argv[3];
if ( !v10 )
{
fputs(ERRMSG3, stderr);
return 1;
}
v3 = strtod(v10, 0LL);
}
v11 = accuracy(v9);
while ( 1 )
{
v13 = __isoc99_scanf();
if ( v13 == -1 )
break;
if ( v13 )
{
if ( v7 )
{
v15 = pwr(v17, v3, v11);
printf("%.10e\n", v15);
}
else if ( v6 )
{
v16 = arctg(v17, v11);
printf("%.10e\n", v16);
}
else if ( v5 )
{
v14 = ash(v17, v11);
printf("%.10e\n", v14);
}
}
else
{
__isoc99_scanf();
printf("%f\n", 0.0 / 0.0);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
double v3; // r14
const char *v4; // rbx
char v5; // r13
char v6; // r12
char v7; // bl
const char *v8; // rdi
int v9; // er15
const char *v10; // rdi
double v11; // rbp
int v13; // eax
double v14; // xmm0_8
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // [rsp+8h] [rbp-40h]

v4 = argv[1];
if ( !v4 )
goto LABEL_12;
if ( strcmp(v4, HELP0) && strcmp(v4, HELP1) )
{
if ( !strcmp(v4, ARG_POW) )
{
v5 = 0;
v6 = 0;
v7 = 1;
goto LABEL_6;
}
if ( !strcmp(v4, ARG_ARCTG) )
{
v5 = 0;
v6 = 1;
v7 = 0;
goto LABEL_6;
}
if ( !strcmp(v4, ARG_ARSINH) )
{
v5 = 1;
v6 = 0;
v7 = 0;
goto LABEL_6;
}
LABEL_12:
fputs(ERRMSG0, stderr);
return 1;
}
if ( (unsigned int)func7() )
return 0;
v5 = 0;
v6 = 0;
v7 = 0;
LABEL_6:
v8 = argv[2];
if ( !v8 || (v9 = atoi(v8), v9 < 0) )
{
fputs(ERRMSG2, stderr);
return 1;
}
if ( v7 )
{
v10 = argv[3];
if ( !v10 )
{
fputs(ERRMSG3, stderr);
return 1;
}
v3 = strtod(v10, 0LL);
}
v11 = func14(v9);
while ( 1 )
{
v13 = __isoc99_scanf();
if ( v13 == -1 )
break;
if ( v13 )
{
if ( v7 )
{
v15 = func11(v17, v3, v11);
printf("%.10e\n", v15);
}
else if ( v6 )
{
v16 = func12(v17, v11);
printf("%.10e\n", v16);
}
else if ( v5 )
{
v14 = func13(v17, v11);
printf("%.10e\n", v14);
}
}
else
{
__isoc99_scanf();
printf("%f\n", 0.0 / 0.0);
}
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 _Bool arg_pow = 0;
 _Bool arg_arctg = 0;
 _Bool arg_arsinh = 0;
 int sd = -1;
 double a;
 _Bool a_flag = 0;
 argc = argc;
 int i=1;
 if (!argv[i]) {
  fprintf(stderr, "%s", ERRMSG0);
  return 1;
 }
 if (!strcmp(argv[i], HELP0) || !strcmp(argv[i], HELP1)) {
  if (print_help()) {
   return 0;
  }
 } else if (!strcmp(argv[i], ARG_POW)) {
  arg_pow = 1;
 } else if (!strcmp(argv[i], ARG_ARCTG)) {
  arg_arctg = 1;
 } else if (!strcmp(argv[i], ARG_ARSINH)) {
  arg_arsinh = 1;
 } else {
  fprintf(stderr, "%s", ERRMSG0);
  return 1;
 }
 if (argv[i+1]) {sd = atoi(argv[i+1]);}
 if(sd<0) {
  fprintf(stderr, "%s", ERRMSG2);
  return 1;
 }
 if ((arg_pow)&&(argv[i+2])) {
  a = strtod (argv[i+2], ((void *)0));
  a_flag = 1;
 }
 if ((arg_pow)&&(!a_flag)) {
  fprintf(stderr, "%s", ERRMSG3);
  return 1;
 }
 double eps = accuracy (sd);
 int temp;
 double x;
 while ((temp = scanf("%lf", &x)) != (-1))
 {
     if (temp == 0) {
      scanf("%*s");
      printf("%f\n", 0.0/0.0);
     } else if (arg_pow) {
      printf("%.10e\n", pwr(x,a,eps));
     } else if (arg_arctg) {
      printf("%.10e\n", arctg(x,eps));
     } else if (arg_arsinh) {
      printf("%.10e\n", ash(x,eps));
     }
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 _Bool arg_pow = 0;
 _Bool arg_arctg = 0;
 _Bool arg_arsinh = 0;
 int sd = -1;
 double a;
 _Bool a_flag = 0;
 argc = argc;
 int i = 1;
 if (!argv[i]) {
  fprintf(stderr, "%s", ERRMSG0);
  return 1;
 }
 if (!strcmp(argv[i], HELP0) || !strcmp(argv[i], HELP1)) {
  if (print_help()) {
   return 0;
  }
 } else if (!strcmp(argv[i], ARG_POW)) {
  arg_pow = 1;
 } else if (!strcmp(argv[i], ARG_ARCTG)) {
  arg_arctg = 1;
 } else if (!strcmp(argv[i], ARG_ARSINH)) {
  arg_arsinh = 1;
 } else {
  fprintf(stderr, "%s", ERRMSG0);
  return 1;
 }
 if (argv[i+1]) {sd = atoi(argv[i+1]);}
 if(sd<0) {
  fprintf(stderr, "%s", ERRMSG2);
  return 1;
 }
 if ((arg_pow)&&(argv[i+2])) {
  a = strtod (argv[i+2], ((void *)0));
  a_flag = 1;
 }
 if ((arg_pow)&&(!a_flag)) {
  fprintf(stderr, "%s", ERRMSG3);
  return 1;
 }
 double eps = accuracy (sd);
 int temp;
 double x;
 while ((temp = scanf("%lf", &x)) != (-1))
 {
     if (temp == 0) {
      scanf("%*s");
      printf("%f\n", 0.0/0.0);
     } else if (arg_pow) {
      printf("%.10e\n", pwr(x,a,eps));
     } else if (arg_arctg) {
      printf("%.10e\n", arctg(x,eps));
     } else if (arg_arsinh) {
      printf("%.10e\n", ash(x,eps));
     }
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: sd int

variable_types: a double

variable_types: eps double

variable_types: temp int

variable_types: x double

return_type: int


repo: kusha/santa-claus-sync

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

do
result = (unsigned int)(rand() / (0x7FFFFFFF / (a1 + 1)));
while ( a1 < (int)result );
return result;
}

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

do
result = (unsigned int)(rand() / (0x7FFFFFFF / (a1 + 1)));
while ( a1 < (int)result );
return result;
}

original_code:
int gen_random (int limit) {
 int divisor = 2147483647/(limit+1);
 int res;
 do {
  res = rand() / divisor;
 } while (res > limit);
 return res;
}

canonical_original_code:
int gen_random(int limit) {
 int divisor = 2147483647/(limit+1);
 int res;
 do {
  res = rand() / divisor;
 } while (res > limit);
 return res;
}

variable_types: limit int

variable_types: divisor int

variable_types: res int


repo: kvisle/awesometd

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // rax

puts(
"======================================================\n"
" AWESOME TOWER DEFENSE\n"
" by Trygve Vea <trygve.vea@gmail.com>\n"
"======================================================");
if ( (int)SDL_Init(33LL, argv) < 0 )
{
v4 = (const char *)SDL_GetError();
printf("SDL_Init failed : %s\n", v4);
result = 1;
}
else
{
init_video();
init_timers();
event_loop();
result = 0;
}
return result;
}


decompiled_code:
__int64 __fastcall update_money(int a1)
{
if ( !idkfa_enabled )
money += a1;
if ( money < 0 )
money = 0;
sprintf(moneytext, "money %6d", (unsigned int)money);
return updaterect(3LL, 13LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
if ( !idkfa_enabled )
money += a1;
if ( money < 0 )
money = 0;
sprintf(moneytext, "money %6d", (unsigned int)money);
return updaterect(3LL, 13LL);
}

original_code:
void update_money(int amount) {
    if (! idkfa_enabled) money += amount;
    if ( money < 0 ) money = 0;
    sprintf(moneytext, "money %6d", money);
    updaterect(3,13);
}

variable_types: amount int

return_type: void


decompiled_code:
__int64 __fastcall update_score(int a1)
{
bool v1; // sf
unsigned int v2; // edi
__int64 v3; // rdx

v1 = score + a1 < 0;
v2 = score + a1;
v3 = 0LL;
if ( !v1 )
v3 = v2;
score = v3;
sprintf(scoretext, "score %6d", v3);
return updaterect(3LL, 13LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
bool v1; // sf
unsigned int v2; // edi
__int64 v3; // rdx

v1 = score + a1 < 0;
v2 = score + a1;
v3 = 0LL;
if ( !v1 )
v3 = v2;
score = v3;
sprintf(scoretext, "score %6d", v3);
return updaterect(3LL, 13LL);
}

original_code:
void update_score(int amount) {
    score += amount;
    if ( score < 0 ) score = 0;
    sprintf(scoretext, "score %6d", score);
    updaterect(3,13);
}


decompiled_code:
__int64 __fastcall update_lives(int a1)
{
if ( !iddqd_enabled )
lives += a1;
if ( lives < 0 )
{
lives = 0;
}
else if ( lives )
{
sprintf(lifetext, "lives %6d", (unsigned int)lives);
return updaterect(3LL, 13LL);
}
return show_highscores(2LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
if ( !iddqd_enabled )
lives += a1;
if ( lives < 0 )
{
lives = 0;
}
else if ( lives )
{
sprintf(lifetext, "lives %6d", (unsigned int)lives);
return updaterect(3LL, 13LL);
}
return show_highscores(2LL);
}

original_code:
void update_lives(int amount) {
    if (! iddqd_enabled) lives += amount;
    if ( lives < 0 ) {
        lives = 0;
    }
    if ( lives == 0 ) {
        show_highscores(2);
        return;
    }
    sprintf(lifetext, "lives %6d", lives);
    updaterect(3,13);
}


decompiled_code:
__int64 new_game()
{
money = 250;
score = 0;
lives = 20;
update_score(0);
update_money(0);
update_lives(0);
reset_everything();
current_screen = 2;
return update_all();
}

canonical_decompiled_code:
__int64 func3()
{
money = 250;
score = 0;
lives = 20;
func1(0);
func0(0);
func2(0);
reset_everything();
current_screen = 2;
return update_all();
}

original_code:
void new_game(void) {
    money = 250;
    score = 0;
    lives = 20;
    update_score(0);
    update_money(0);
    update_lives(0);
    reset_everything();
    current_screen = 2;
    update_all();
}

canonical_original_code:
void new_game() {
    money = 250;
    score = 0;
    lives = 20;
    update_score(0);
    update_money(0);
    update_lives(0);
    reset_everything();
    current_screen = 2;
    update_all();
}


decompiled_code:
_BOOL8 __fastcall have_money(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( !idkfa_enabled )
result = money >= a1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( !idkfa_enabled )
result = money >= a1;
return result;
}

original_code:
int have_money(int amount) {
    if (idkfa_enabled) return 1;
    if ( money >= amount ) return 1;
    return 0;
}


decompiled_code:
__int64 draw_numbers()
{
draw_text(screen, moneytext, 96LL, 420LL);
draw_text(screen, scoretext, 96LL, 430LL);
draw_text(screen, lifetext, 96LL, 440LL);
return draw_numbers2();
}

canonical_decompiled_code:
__int64 func5()
{
draw_text(screen, moneytext, 96LL, 420LL);
draw_text(screen, scoretext, 96LL, 430LL);
draw_text(screen, lifetext, 96LL, 440LL);
return draw_numbers2();
}

original_code:
void draw_numbers(void) {
    draw_text(screen,moneytext,3*32,420);
    draw_text(screen,scoretext,3*32,430);
    draw_text(screen,lifetext,3*32,440);
    draw_numbers2();
}

canonical_original_code:
void draw_numbers() {
    draw_text(screen,moneytext,3*32,420);
    draw_text(screen,scoretext,3*32,430);
    draw_text(screen,lifetext,3*32,440);
    draw_numbers2();
}


decompiled_code:
__int64 draw_highscore_stats()
{
char s[48]; // [rsp+0h] [rbp-30h] BYREF

sprintf(s, "you 1 %2d %6d", batch, (unsigned int)score);
return draw_text(screen, s, 104LL, 152LL);
}

canonical_decompiled_code:
__int64 func6()
{
char s[48]; // [rsp+0h] [rbp-30h] BYREF

sprintf(s, "you 1 %2d %6d", batch, (unsigned int)score);
return draw_text(screen, s, 104LL, 152LL);
}

original_code:
void draw_highscore_stats(void) {
    char line[46];
    sprintf(line, "you                         1     %2d   %6d", batch, score);
    draw_text(screen,line,104,152);
}

canonical_original_code:
void draw_highscore_stats() {
    char line[46];
    sprintf(line, "you                         1     %2d   %6d", batch, score);
    draw_text(screen,line,104,152);
}

variable_types:
line
char [46]


iddqd

decompiled_code:
__int64 iddqd()
{
iddqd_enabled = 1;
lives = 999;
return update_lives(0);
}

canonical_decompiled_code:
__int64 func7()
{
iddqd_enabled = 1;
lives = 999;
return func2(0);
}

original_code:
void iddqd(void)
{
    iddqd_enabled = 1;
    lives = 999;
    update_lives(0);
}

canonical_original_code:
void iddqd()
{
    iddqd_enabled = 1;
    lives = 999;
    update_lives(0);
}


idkfa

decompiled_code:
__int64 idkfa()
{
idkfa_enabled = 1;
money = 999999;
return update_money(0);
}

canonical_decompiled_code:
__int64 func8()
{
idkfa_enabled = 1;
money = 999999;
return func0(0);
}

original_code:
void idkfa(void)
{
    idkfa_enabled = 1;
    money = 999999;
    update_money(0);
}

canonical_original_code:
void idkfa()
{
    idkfa_enabled = 1;
    money = 999999;
    update_money(0);
}


decompiled_code:
__int64 draw_stuff_on_top()
{
__int64 result; // rax
__int64 v1; // r15
int v2; // er13
unsigned int v3; // er12
__int64 i; // rbx
unsigned int v5; // eax
unsigned int v6; // eax
__int16 v7; // [rsp+0h] [rbp-40h] BYREF
__int16 v8; // [rsp+2h] [rbp-3Eh]
__int16 v9; // [rsp+4h] [rbp-3Ch]
__int16 v10; // [rsp+6h] [rbp-3Ah]
char v11[4]; // [rsp+8h] [rbp-38h] BYREF
char v12[52]; // [rsp+Ch] [rbp-34h] BYREF

get_cursor_location(v12, v11);
result = (unsigned int)current_screen;
switch ( current_screen )
{
case 1:
result = dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1400 | dword_13C4 | dword_1388 | dword_134C | dword_13FC | dword_13C0 | dword_1384 | (unsigned int)dword_1348;
if ( dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1400 | dword_13C4 | dword_1388 | dword_134C | dword_13FC | dword_13C0 | dword_1384 | dword_1348 )
result = draw_menu();
return result;
case 2:
draw_cursor(screen);
v1 = 0LL;
v2 = 0;
v3 = 0;
break;
case 3:
return draw_highscores();
case 4:
return draw_credits();
case 5:
return draw_tutorial();
default:
return result;
}
while ( 2 )
{
for ( i = 0LL; i != 15; ++i )
{
if ( v2 == 0 && (int)v3 > 7 && (int)i > 12 )
{
v2 = field[i + v1];
if ( v2 != 1 )
{
v2 = 0;
continue;
}
draw_hint_text(screen);
draw_buttons(screen);
draw_text_color(screen, costtext, 265LL, 416LL, 255LL, 255LL, 0LL);
}
if ( field[i + v1] == 1 )
{
draw_tower(v3, (unsigned int)i);
draw_enemy(v3, (unsigned int)i);
draw_projectile(v3, (unsigned int)i);
}
}
++v3;
v1 += 15LL;
if ( v3 != 20 )
continue;
break;
}
if ( dword_1114 == 1 )
{
v7 = 96;
v8 = 0;
v9 = 32;
v10 = 32;
v5 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, &v7, v5);
}
if ( dword_14DC == 1 )
{
v7 = 608;
v8 = 64;
v9 = 32;
v10 = 32;
v6 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, &v7, v6);
}
if ( dword_145C == 1 || dword_1498 == 1 || dword_14D4 == 1 )
draw_text(screen, fpstext, 520LL, 0LL);
if ( dword_12B4 | dword_1278 | dword_123C | dword_1200 | dword_11C4 | dword_1188 | dword_114C | dword_1110 | dword_12B0 | dword_1274 | dword_1238 | dword_11FC | dword_11C0 | dword_1184 | dword_1148 | dword_110C )
draw_numbers();
if ( dword_14D4 | dword_1498 | dword_145C | dword_1420 )
draw_text(screen, fpstext, 520LL, 0LL);
result = dword_13E4 | dword_13A8 | dword_136C | dword_1330 | dword_12F4 | dword_12B8 | dword_127C | (unsigned int)dword_1240;
if ( dword_13E4 | dword_13A8 | dword_136C | dword_1330 | dword_12F4 | dword_12B8 | dword_127C | dword_1240 )
result = draw_buttons2(screen);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // r15
int v2; // er13
unsigned int v3; // er12
__int64 i; // rbx
unsigned int v5; // eax
unsigned int v6; // eax
__int16 v7; // [rsp+0h] [rbp-40h] BYREF
__int16 v8; // [rsp+2h] [rbp-3Eh]
__int16 v9; // [rsp+4h] [rbp-3Ch]
__int16 v10; // [rsp+6h] [rbp-3Ah]
char v11[4]; // [rsp+8h] [rbp-38h] BYREF
char v12[52]; // [rsp+Ch] [rbp-34h] BYREF

get_cursor_location(v12, v11);
result = (unsigned int)current_screen;
switch ( current_screen )
{
case 1:
result = dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1400 | dword_13C4 | dword_1388 | dword_134C | dword_13FC | dword_13C0 | dword_1384 | (unsigned int)dword_1348;
if ( dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1400 | dword_13C4 | dword_1388 | dword_134C | dword_13FC | dword_13C0 | dword_1384 | dword_1348 )
result = draw_menu();
return result;
case 2:
draw_cursor(screen);
v1 = 0LL;
v2 = 0;
v3 = 0;
break;
case 3:
return draw_highscores();
case 4:
return draw_credits();
case 5:
return draw_tutorial();
default:
return result;
}
while ( 2 )
{
for ( i = 0LL; i != 15; ++i )
{
if ( v2 == 0 && (int)v3 > 7 && (int)i > 12 )
{
v2 = field[i + v1];
if ( v2 != 1 )
{
v2 = 0;
continue;
}
draw_hint_text(screen);
draw_buttons(screen);
draw_text_color(screen, costtext, 265LL, 416LL, 255LL, 255LL, 0LL);
}
if ( field[i + v1] == 1 )
{
draw_tower(v3, (unsigned int)i);
draw_enemy(v3, (unsigned int)i);
draw_projectile(v3, (unsigned int)i);
}
}
++v3;
v1 += 15LL;
if ( v3 != 20 )
continue;
break;
}
if ( dword_1114 == 1 )
{
v7 = 96;
v8 = 0;
v9 = 32;
v10 = 32;
v5 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, &v7, v5);
}
if ( dword_14DC == 1 )
{
v7 = 608;
v8 = 64;
v9 = 32;
v10 = 32;
v6 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, &v7, v6);
}
if ( dword_145C == 1 || dword_1498 == 1 || dword_14D4 == 1 )
draw_text(screen, fpstext, 520LL, 0LL);
if ( dword_12B4 | dword_1278 | dword_123C | dword_1200 | dword_11C4 | dword_1188 | dword_114C | dword_1110 | dword_12B0 | dword_1274 | dword_1238 | dword_11FC | dword_11C0 | dword_1184 | dword_1148 | dword_110C )
draw_numbers();
if ( dword_14D4 | dword_1498 | dword_145C | dword_1420 )
draw_text(screen, fpstext, 520LL, 0LL);
result = dword_13E4 | dword_13A8 | dword_136C | dword_1330 | dword_12F4 | dword_12B8 | dword_127C | (unsigned int)dword_1240;
if ( dword_13E4 | dword_13A8 | dword_136C | dword_1330 | dword_12F4 | dword_12B8 | dword_127C | dword_1240 )
result = draw_buttons2(screen);
return result;
}

original_code:
static void draw_stuff_on_top(void) {
    int x,y;
    int m_x, m_y;
    int drawn_helptext = 0;
    int drawn_buttons = 0;
    get_cursor_location(&m_x, &m_y);
    switch(current_screen) {
        case 4:
            draw_credits();
        break;
        case 3:
            draw_highscores();
        break;
        case 5:
            draw_tutorial();
        break;
        case 1:
            if (
                field[12][6] || field[13][6] || field[14][6] || field[15][6] ||
                field[12][7] || field[13][7] || field[14][7] || field[15][7] ||
                field[12][8] || field[13][8] || field[14][8] || field[15][8]
                ) {
                draw_menu();
            }
        break;
        case 2:
            draw_cursor(screen);
            for (x=0;x<20;x++) {
                for (y=0;y<15;y++) {
                    if ( x >= 8 && y >= 13 && drawn_helptext == 0 && field[x][y] == 1 ) {
                        drawn_helptext = 1;
                        draw_hint_text(screen);
                        drawn_buttons = 1;
                        draw_buttons(screen);
                        draw_text_color(screen,costtext,265,416,255,255,0);
                    }
                    if ( field[x][y] == 1 ) {
                        draw_tower(x,y);
                        draw_enemy(x,y);
                        draw_projectile(x,y);
                    }
                }
            }
            if ( field[3][0] == 1 ) {
                SDL_Rect rect = { 3*32, 0*32, 32, 32 };
                SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,0,0,0));
            }
            if ( field[19][2] == 1 ) {
                SDL_Rect rect = { 19*32, 2*32, 32, 32 };
                SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,0,0,0));
            }
            if ( field[17][0] == 1 || field[18][0] == 1 || field[19][0] == 1) {
                draw_text(screen, fpstext, 520, 0);
            }
            if ( field[2][13] || field[3][13] || field[4][13] || field[5][13] || field[6][13] || field[7][13] || field[8][13] || field[9][13] ||
                 field[2][14] || field[3][14] || field[4][14] || field[5][14] || field[6][14] || field[7][14] || field[8][14] || field[9][14]
                 ) {
                draw_numbers();
            }
            if ( field[16][0] || field[17][0] || field[18][0] || field[19][0] )
                draw_text(screen, fpstext, 520, 0);
            if ( field[8][0] || field[9][0] || field[10][0] || field[11][0] || field[12][0] || field[13][0] || field[14][0] || field[15][0] ) {
                draw_buttons2(screen);
            }
        break;
    }
}

canonical_original_code:
static void draw_stuff_on_top() {
    int x; int y;
    int m_x; int m_y;
    int drawn_helptext = 0;
    int drawn_buttons = 0;
    get_cursor_location(&m_x, &m_y);
    switch(current_screen) {
        case 4:
            draw_credits();
        break;
        case 3:
            draw_highscores();
        break;
        case 5:
            draw_tutorial();
        break;
        case 1:
            if (
                field[12][6] || field[13][6] || field[14][6] || field[15][6] ||
                field[12][7] || field[13][7] || field[14][7] || field[15][7] ||
                field[12][8] || field[13][8] || field[14][8] || field[15][8]
                ) {
                draw_menu();
            }
        break;
        case 2:
            draw_cursor(screen);
            for (x=0;x<20;x++) {
                for (y=0;y<15;y++) {
                    if ( x >= 8 && y >= 13 && drawn_helptext == 0 && field[x][y] == 1 ) {
                        drawn_helptext = 1;
                        draw_hint_text(screen);
                        drawn_buttons = 1;
                        draw_buttons(screen);
                        draw_text_color(screen,costtext,265,416,255,255,0);
                    }
                    if ( field[x][y] == 1 ) {
                        draw_tower(x,y);
                        draw_enemy(x,y);
                        draw_projectile(x,y);
                    }
                }
            }
            if ( field[3][0] == 1 ) {
                struct SDL_Rect rect = { 3*32, 0*32, 32, 32 };
                SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,0,0,0));
            }
            if ( field[19][2] == 1 ) {
                struct SDL_Rect rect = { 19*32, 2*32, 32, 32 };
                SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format,0,0,0));
            }
            if ( field[17][0] == 1 || field[18][0] == 1 || field[19][0] == 1) {
                draw_text(screen, fpstext, 520, 0);
            }
            if ( field[2][13] || field[3][13] || field[4][13] || field[5][13] || field[6][13] || field[7][13] || field[8][13] || field[9][13] ||
                 field[2][14] || field[3][14] || field[4][14] || field[5][14] || field[6][14] || field[7][14] || field[8][14] || field[9][14]
                 ) {
                draw_numbers();
            }
            if ( field[16][0] || field[17][0] || field[18][0] || field[19][0] )
                draw_text(screen, fpstext, 520, 0);
            if ( field[8][0] || field[9][0] || field[10][0] || field[11][0] || field[12][0] || field[13][0] || field[14][0] || field[15][0] ) {
                draw_buttons2(screen);
            }
        break;
    }
}

variable_types: x int

variable_types: y int

variable_types: struct SDL_Rect { short x; unsigned short w; }


render

decompiled_code:
__int64 render()
{
__int64 result; // rax

draw_stuff_on_top();
if ( updatefield > 0 )
{
memset(field, 0, 0x4B0uLL);
SDL_UpdateRects(screen, (unsigned int)updatefield, &word_6C4);
updatefield = 0;
}
result = mark_rendered();
++rendercount;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

func0();
if ( updatefield > 0 )
{
memset(field, 0, 0x4B0uLL);
SDL_UpdateRects(screen, (unsigned int)updatefield, &word_6C4);
updatefield = 0;
}
result = mark_rendered();
++rendercount;
return result;
}

original_code:
void render(void) {
    draw_stuff_on_top();
    if ( updatefield.count > 0 ) {
        memset(&field, 0x00, sizeof(int)*(640/32)*(480/32));
        SDL_UpdateRects(screen, updatefield.count, (SDL_Rect *) &updatefield.rects);
        updatefield.count = 0;
    }
    mark_rendered();
    rendercount++;
}

canonical_original_code:
void render() {
    draw_stuff_on_top();
    if ( updatefield.count > 0 ) {
        memset(&field, 0x00, sizeof(int)*(640/32)*(480/32));
        SDL_UpdateRects(screen, updatefield.count, (struct SDL_Rect *) &updatefield.rects);
        updatefield.count = 0;
    }
    mark_rendered();
    rendercount++;
}

user_defined_types: struct SDL_Rect { short x; unsigned short w; }


getrenders

decompiled_code:
__int64 getrenders()
{
unsigned int v0; // ebx

v0 = rendercount;
sprintf(fpstext, "%11d fps", (unsigned int)rendercount);
rendercount = 0;
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

v0 = rendercount;
sprintf(fpstext, "%11d fps", (unsigned int)rendercount);
rendercount = 0;
return v0;
}

original_code:
int getrenders(void) {
    int i = rendercount;
    sprintf(fpstext, "%11d fps", i);
    rendercount = 0;
    return i;
}

canonical_original_code:
int getrenders() {
    int i = rendercount;
    sprintf(fpstext, "%11d fps", i);
    rendercount = 0;
    return i;
}


updaterect

decompiled_code:
void __fastcall updaterect(int a1, int a2)
{
__int64 v2; // rax

if ( a1 <= 19 && a2 <= 14 && !field[15 * a1 + a2] )
{
field[15 * a1 + a2] = 1;
v2 = updatefield;
word_6C4[4 * updatefield] = 32 * a1;
word_6C6[4 * v2] = 32 * a2;
word_6C8[4 * v2] = 32;
word_6CA[4 * v2] = 32;
if ( current_screen == 2 )
SDL_UpperBlit(background, &word_6C4[4 * v2], screen, &word_6C4[4 * v2]);
if ( (unsigned int)(current_screen - 3) <= 2 || current_screen == 1 )
SDL_UpperBlit(menubackground, &word_6C4[4 * updatefield], screen, &word_6C4[4 * updatefield]);
++updatefield;
}
}

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

if ( a1 <= 19 && a2 <= 14 && !field[15 * a1 + a2] )
{
field[15 * a1 + a2] = 1;
v2 = updatefield;
word_6C4[4 * updatefield] = 32 * a1;
word_6C6[4 * v2] = 32 * a2;
word_6C8[4 * v2] = 32;
word_6CA[4 * v2] = 32;
if ( current_screen == 2 )
SDL_UpperBlit(background, &word_6C4[4 * v2], screen, &word_6C4[4 * v2]);
if ( (unsigned int)(current_screen - 3) <= 2 || current_screen == 1 )
SDL_UpperBlit(menubackground, &word_6C4[4 * updatefield], screen, &word_6C4[4 * updatefield]);
++updatefield;
}
}

original_code:
void updaterect(int x, int y) {
    if ( x < 20 && y < 15 ) {
        if ( field[x][y] == 0 ) {
            field[x][y] = 1;
            updatefield.rects[updatefield.count].x = x * 32;
            updatefield.rects[updatefield.count].y = y * 32;
            updatefield.rects[updatefield.count].w = 32;
            updatefield.rects[updatefield.count].h = 32;
            if ( current_screen == 2 )
                SDL_UpperBlit(background, &updatefield.rects[updatefield.count], screen, &updatefield.rects[updatefield.count]);
            if ( current_screen == 1 || current_screen == 4 || current_screen == 3 || current_screen == 5 )
                SDL_UpperBlit(menubackground, &updatefield.rects[updatefield.count], screen, &updatefield.rects[updatefield.count]);
            updatefield.count++;
        }
    }
}


decompiled_code:
void update_all()
{
int i; // er12
int j; // ebx

if ( current_screen == 2 )
SDL_UpperBlit(background, 0LL, screen, 0LL);
if ( (current_screen & 0xFFFFFFFD) == 1 )
SDL_UpperBlit(menubackground, 0LL, screen, 0LL);
for ( i = 0; i != 20; ++i )
{
for ( j = 0; j != 15; ++j )
updaterect(i, j);
}
}

canonical_decompiled_code:
void func4()
{
int i; // er12
int j; // ebx

if ( current_screen == 2 )
SDL_UpperBlit(background, 0LL, screen, 0LL);
if ( (current_screen & 0xFFFFFFFD) == 1 )
SDL_UpperBlit(menubackground, 0LL, screen, 0LL);
for ( i = 0; i != 20; ++i )
{
for ( j = 0; j != 15; ++j )
func3(i, j);
}
}

original_code:
void update_all(void) {
    int x, y;
    if ( current_screen == 2 ) SDL_UpperBlit(background, ((void *)0), screen, ((void *)0));
    if ( current_screen == 1 || current_screen == 3 ) SDL_UpperBlit(menubackground, ((void *)0), screen, ((void *)0));
    for (x=0;x<20;x++) {
        for (y=0;y<15;y++) {
            updaterect(x,y);
        }
    }
}

canonical_original_code:
void update_all() {
    int x; int y;
    if ( current_screen == 2 ) SDL_UpperBlit(background, ((void *)0), screen, ((void *)0));
    if ( current_screen == 1 || current_screen == 3 ) SDL_UpperBlit(menubackground, ((void *)0), screen, ((void *)0));
    for (x=0;x<20;x++) {
        for (y=0;y<15;y++) {
            updaterect(x,y);
        }
    }
}


decompiled_code:
__int64 init_video()
{
__int64 v0; // rax
unsigned int v1; // eax

screen = SDL_SetVideoMode(640LL, 480LL, 32LL, 1LL);
SDL_WM_SetCaption("Awesome Tower Defense 0.3", &unk_1559);
background = SDL_CreateRGBSurface(1LL, 640LL, 480LL, 32LL, 255LL, 65280LL, 16711680LL, -16777216LL);
v0 = SDL_RWFromMem(&binary_menuscreen_bmp_start, &binary_menuscreen_bmp_end - &binary_menuscreen_bmp_start);
menubackground = SDL_LoadBMP_RW(v0, 0LL);
init_sprites();
init_buttons();
v1 = SDL_MapRGB(*(_QWORD *)(background + 8), 0LL, 0LL, 0LL);
SDL_FillRect(background, 0LL, v1);
load_level(background, 0LL);
update_all();
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
unsigned int v1; // eax

screen = SDL_SetVideoMode(640LL, 480LL, 32LL, 1LL);
SDL_WM_SetCaption("Awesome Tower Defense 0.3", &unk_1559);
background = SDL_CreateRGBSurface(1LL, 640LL, 480LL, 32LL, 255LL, 65280LL, 16711680LL, -16777216LL);
v0 = SDL_RWFromMem(&binary_menuscreen_bmp_start, &binary_menuscreen_bmp_end - &binary_menuscreen_bmp_start);
menubackground = SDL_LoadBMP_RW(v0, 0LL);
init_sprites();
init_buttons();
v1 = SDL_MapRGB(*(_QWORD *)(background + 8), 0LL, 0LL, 0LL);
SDL_FillRect(background, 0LL, v1);
load_level(background, 0LL);
func4();
return 0LL;
}

original_code:
int init_video(void) {
    screen = SDL_SetVideoMode(640, 480, 32, 0x00000001);
    SDL_WM_SetCaption("Awesome Tower Defense 0.3","");
    background = SDL_CreateRGBSurface(0x00000001, 640, 480, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
    menubackground = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_menuscreen_bmp_start),(&_binary_menuscreen_bmp_end - &_binary_menuscreen_bmp_start)),0);
    init_sprites();
    init_buttons();
    SDL_FillRect(background, ((void *)0), SDL_MapRGB(background->format,0,0,0));
    load_level(background, 0);
    update_all();
    return 0;
}

canonical_original_code:
int init_video() {
    screen = SDL_SetVideoMode(640, 480, 32, 0x00000001);
    SDL_WM_SetCaption("Awesome Tower Defense 0.3","");
    background = SDL_CreateRGBSurface(0x00000001, 640, 480, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
    menubackground = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_menuscreen_bmp_start),(&_binary_menuscreen_bmp_end - &_binary_menuscreen_bmp_start)),0);
    init_sprites();
    init_buttons();
    SDL_FillRect(background, ((void *)0), SDL_MapRGB(background->format,0,0,0));
    load_level(background, 0);
    update_all();
    return 0;
}


decompiled_code:
__int64 __fastcall show_highscores(int a1)
{
messageno = a1;
current_screen = 3;
return update_all();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
messageno = a1;
current_screen = 3;
return update_all();
}

original_code:
void show_highscores(int message) {
    messageno = message;
    current_screen = 3;
    update_all();
}

variable_types: message int


decompiled_code:
__int64 draw_highscores()
{
__int64 result; // rax

draw_text(screen, "player level batch score", 104LL, 136LL);
draw_text(screen, "this is still not implemented", 200LL, 200LL);
result = draw_text(screen, (char *)&messages + 50 * messageno, 200LL, 250LL);
if ( messageno > 0 )
result = draw_highscore_stats();
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

draw_text(screen, "player level batch score", 104LL, 136LL);
draw_text(screen, "this is still not implemented", 200LL, 200LL);
result = draw_text(screen, (char *)&messages + 50 * messageno, 200LL, 250LL);
if ( messageno > 0 )
result = draw_highscore_stats();
return result;
}

original_code:
void draw_highscores(void) {
    draw_text(screen,"player                    level  batch  score",104,136);
    draw_text(screen,"this is still not implemented",200,200);
    draw_text(screen,messages[messageno],200,250);
    if ( messageno > 0 ) {
        draw_highscore_stats();
    }
}

canonical_original_code:
void draw_highscores() {
    draw_text(screen,"player                    level  batch  score",104,136);
    draw_text(screen,"this is still not implemented",200,200);
    draw_text(screen,messages[messageno],200,250);
    if ( messageno > 0 ) {
        draw_highscore_stats();
    }
}


decompiled_code:
int load_sprites()
{
__int64 v0; // rax
__int64 v1; // rax
int result; // eax

v0 = SDL_RWFromMem(&binary_tut_basic_bmp_start, &binary_tut_basic_bmp_end - &binary_tut_basic_bmp_start);
tut_basic = SDL_LoadBMP_RW(v0, 0LL);
v1 = SDL_RWFromMem(&binary_tut_upgrading_bmp_start, &binary_tut_upgrading_bmp_end - &binary_tut_upgrading_bmp_start);
tut_upgrading = SDL_LoadBMP_RW(v1, 0LL);
result = puts("sprites loaded!");
sprites_loaded = 1;
return result;
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rax
__int64 v1; // rax
int result; // eax

v0 = SDL_RWFromMem(&binary_tut_basic_bmp_start, &binary_tut_basic_bmp_end - &binary_tut_basic_bmp_start);
tut_basic = SDL_LoadBMP_RW(v0, 0LL);
v1 = SDL_RWFromMem(&binary_tut_upgrading_bmp_start, &binary_tut_upgrading_bmp_end - &binary_tut_upgrading_bmp_start);
tut_upgrading = SDL_LoadBMP_RW(v1, 0LL);
result = puts("sprites loaded!");
sprites_loaded = 1;
return result;
}

original_code:
static void load_sprites(void) {
    tut_basic = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_tut_basic_bmp_start),(&_binary_tut_basic_bmp_end - &_binary_tut_basic_bmp_start)),0);
    tut_upgrading = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_tut_upgrading_bmp_start),(&_binary_tut_upgrading_bmp_end - &_binary_tut_upgrading_bmp_start)),0);
    printf("sprites loaded!\n");
    sprites_loaded = 1;
}

canonical_original_code:
static void load_sprites() {
    tut_basic = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_tut_basic_bmp_start),(&_binary_tut_basic_bmp_end - &_binary_tut_basic_bmp_start)),0);
    tut_upgrading = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_tut_upgrading_bmp_start),(&_binary_tut_upgrading_bmp_end - &_binary_tut_upgrading_bmp_start)),0);
    printf("sprites loaded!\n");
    sprites_loaded = 1;
}


decompiled_code:
__int64 show_tutorial()
{
current_screen = 5;
redraw = 1;
return update_all();
}

canonical_decompiled_code:
__int64 func1()
{
current_screen = 5;
redraw = 1;
return update_all();
}

original_code:
void show_tutorial(void) {
    current_screen = 5;
    redraw = 1;
    update_all();
}

canonical_original_code:
void show_tutorial() {
    current_screen = 5;
    redraw = 1;
    update_all();
}


decompiled_code:
void draw_tutorial()
{
unsigned int v0; // er12
__int64 v1; // rbx
__int64 v2; // [rsp+0h] [rbp-20h]
__int64 v3; // [rsp+0h] [rbp-20h]
__int64 v4; // [rsp+0h] [rbp-20h]
__int64 v5; // [rsp+0h] [rbp-20h]
__int64 v6; // [rsp+0h] [rbp-20h]
__int64 v7; // [rsp+0h] [rbp-20h]
__int64 v8; // [rsp+0h] [rbp-20h]
__int64 v9; // [rsp+0h] [rbp-20h]
__int64 v10; // [rsp+0h] [rbp-20h]
__int64 v11; // [rsp+0h] [rbp-20h]
__int64 v12; // [rsp+0h] [rbp-20h]

if ( !sprites_loaded )
load_sprites();
if ( redraw )
{
v0 = 160;
v1 = 0LL;
do
{
if ( hoverchoice == (_DWORD)v1 )
draw_text_color(screen, tutorials[v1], 16LL, v0, 255LL, 255LL, 0LL);
else
draw_text(screen, tutorials[v1], 16LL, v0);
++v1;
v0 += 16;
}
while ( v0 != 224 );
update_all();
if ( hoverchoice == 2 )
{
draw_text(screen, "you can control how the towers determine which target", 200LL, 160LL);
draw_text(screen, "to aim for. when you click a tower, a row of buttons", 200LL, 176LL);
draw_text(screen, "will appear on the top of the screen. the buttons let", 200LL, 192LL);
draw_text(screen, "you pick between 5 algorithms.", 200LL, 208LL);
word_9CA = 232;
word_9C2 = 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the least", 232LL, 240LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the farthest", 232LL, 272LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with most hp", 232LL, 304LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with least hp", 232LL, 336LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot the fastest enemy", 232LL, 368LL);
}
else if ( hoverchoice > 2 )
{
if ( hoverchoice == 3 )
{
draw_text_color(screen, "1", 232LL, 160LL, 0LL, 255LL, 255LL);
draw_text(screen, "build pillbox", 280LL, 160LL);
LODWORD(v2) = 255;
draw_text_color(screen, "2", 232LL, 176LL, 0LL, 255LL, v2);
draw_text(screen, "build artificial volcano", 280LL, 176LL);
LODWORD(v3) = 255;
draw_text_color(screen, "3", 232LL, 192LL, 0LL, 255LL, v3);
draw_text(screen, "build freezer", 280LL, 192LL);
LODWORD(v4) = 255;
draw_text_color(screen, "s", 232LL, 208LL, 0LL, 255LL, v4);
draw_text(screen, "sell tower", 280LL, 208LL);
LODWORD(v5) = 255;
draw_text_color(screen, "q", 232LL, 224LL, 0LL, 255LL, v5);
draw_text(screen, "shoot enemy travelled the least", 280LL, 224LL);
LODWORD(v6) = 255;
draw_text_color(screen, "w", 232LL, 240LL, 0LL, 255LL, v6);
draw_text(screen, "shoot enemy travelled the farthest", 280LL, 240LL);
LODWORD(v7) = 255;
draw_text_color(screen, "e", 232LL, 256LL, 0LL, 255LL, v7);
draw_text(screen, "shoot enemy with most hp", 280LL, 256LL);
LODWORD(v8) = 255;
draw_text_color(screen, "r", 232LL, 272LL, 0LL, 255LL, v8);
draw_text(screen, "shoot enemy with least hp", 280LL, 272LL);
LODWORD(v9) = 255;
draw_text_color(screen, "t", 232LL, 288LL, 0LL, 255LL, v9);
draw_text(screen, "shoot the fastest enemy", 280LL, 288LL);
LODWORD(v10) = 255;
draw_text_color(screen, "p", 232LL, 304LL, 0LL, 255LL, v10);
draw_text(screen, "pause tower", 280LL, 304LL);
LODWORD(v11) = 255;
draw_text_color(screen, "space", 232LL, 320LL, 0LL, 255LL, v11);
draw_text(screen, "pause the game", 280LL, 320LL);
LODWORD(v12) = 255;
draw_text_color(screen, "esc", 232LL, 336LL, 0LL, 255LL, v12);
draw_text(screen, "quit to menu", 280LL, 336LL);
}
}
else if ( hoverchoice )
{
if ( hoverchoice == 1 )
{
SDL_UpperBlit(tut_upgrading, 0LL, screen, &tut_upgrading_rect);
draw_text(screen, "when a tower makes a killing blow", 200LL, 160LL);
draw_text(screen, "it earns experience. the yellow", 200LL, 176LL);
draw_text(screen, "bar indicates how far it is from", 200LL, 192LL);
draw_text(screen, "an upgrade. when a tower is fully", 200LL, 208LL);
draw_text(screen, "upgraded it will not gain more", 200LL, 224LL);
draw_text(screen, "experience. the killing blow goes", 200LL, 240LL);
draw_text(screen, "to the last upgradeable tower who", 200LL, 256LL);
draw_text(screen, "made a hit on the enemy. the", 200LL, 272LL);
draw_text(screen, "trick is to position the towers", 200LL, 288LL);
draw_text(screen, "in a way that makes sure that as little experience", 200LL, 304LL);
draw_text(screen, "as possible are wasted.", 200LL, 320LL);
}
}
else
{
SDL_UpperBlit(tut_basic, 0LL, screen, &tut_basic_rect);
draw_text(screen, "enemies will move down a road, if", 360LL, 160LL);
draw_text(screen, "they don't get killed before they", 360LL, 176LL);
draw_text(screen, "get to the end you lose a life.", 360LL, 192LL);
draw_text(screen, "the goal is to survive all the", 360LL, 208LL);
draw_text(screen, "upcoming waves of enemies. when", 360LL, 224LL);
draw_text(screen, "you kill an enemy, you recieve", 360LL, 240LL);
draw_text(screen, "money and points for each kill.", 360LL, 256LL);
draw_text(screen, "the amount of money you get only", 360LL, 272LL);
draw_text(screen, "depend on the enemy you kill.", 360LL, 288LL);
draw_text(screen, "the amount of points you get depend on how far the", 200LL, 304LL);
draw_text(screen, "enemy have travelled along the route. earlier kill", 200LL, 320LL);
draw_text(screen, "means more points.", 200LL, 336LL);
}
redraw = 0;
}
}

canonical_decompiled_code:
void func2()
{
unsigned int v0; // er12
__int64 v1; // rbx
__int64 v2; // [rsp+0h] [rbp-20h]
__int64 v3; // [rsp+0h] [rbp-20h]
__int64 v4; // [rsp+0h] [rbp-20h]
__int64 v5; // [rsp+0h] [rbp-20h]
__int64 v6; // [rsp+0h] [rbp-20h]
__int64 v7; // [rsp+0h] [rbp-20h]
__int64 v8; // [rsp+0h] [rbp-20h]
__int64 v9; // [rsp+0h] [rbp-20h]
__int64 v10; // [rsp+0h] [rbp-20h]
__int64 v11; // [rsp+0h] [rbp-20h]
__int64 v12; // [rsp+0h] [rbp-20h]

if ( !sprites_loaded )
func0();
if ( redraw )
{
v0 = 160;
v1 = 0LL;
do
{
if ( hoverchoice == (_DWORD)v1 )
draw_text_color(screen, tutorials[v1], 16LL, v0, 255LL, 255LL, 0LL);
else
draw_text(screen, tutorials[v1], 16LL, v0);
++v1;
v0 += 16;
}
while ( v0 != 224 );
update_all();
if ( hoverchoice == 2 )
{
draw_text(screen, "you can control how the towers determine which target", 200LL, 160LL);
draw_text(screen, "to aim for. when you click a tower, a row of buttons", 200LL, 176LL);
draw_text(screen, "will appear on the top of the screen. the buttons let", 200LL, 192LL);
draw_text(screen, "you pick between 5 algorithms.", 200LL, 208LL);
word_9CA = 232;
word_9C2 = 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the least", 232LL, 240LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the farthest", 232LL, 272LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with most hp", 232LL, 304LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with least hp", 232LL, 336LL);
word_9CA += 32;
word_9C2 += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot the fastest enemy", 232LL, 368LL);
}
else if ( hoverchoice > 2 )
{
if ( hoverchoice == 3 )
{
draw_text_color(screen, "1", 232LL, 160LL, 0LL, 255LL, 255LL);
draw_text(screen, "build pillbox", 280LL, 160LL);
LODWORD(v2) = 255;
draw_text_color(screen, "2", 232LL, 176LL, 0LL, 255LL, v2);
draw_text(screen, "build artificial volcano", 280LL, 176LL);
LODWORD(v3) = 255;
draw_text_color(screen, "3", 232LL, 192LL, 0LL, 255LL, v3);
draw_text(screen, "build freezer", 280LL, 192LL);
LODWORD(v4) = 255;
draw_text_color(screen, "s", 232LL, 208LL, 0LL, 255LL, v4);
draw_text(screen, "sell tower", 280LL, 208LL);
LODWORD(v5) = 255;
draw_text_color(screen, "q", 232LL, 224LL, 0LL, 255LL, v5);
draw_text(screen, "shoot enemy travelled the least", 280LL, 224LL);
LODWORD(v6) = 255;
draw_text_color(screen, "w", 232LL, 240LL, 0LL, 255LL, v6);
draw_text(screen, "shoot enemy travelled the farthest", 280LL, 240LL);
LODWORD(v7) = 255;
draw_text_color(screen, "e", 232LL, 256LL, 0LL, 255LL, v7);
draw_text(screen, "shoot enemy with most hp", 280LL, 256LL);
LODWORD(v8) = 255;
draw_text_color(screen, "r", 232LL, 272LL, 0LL, 255LL, v8);
draw_text(screen, "shoot enemy with least hp", 280LL, 272LL);
LODWORD(v9) = 255;
draw_text_color(screen, "t", 232LL, 288LL, 0LL, 255LL, v9);
draw_text(screen, "shoot the fastest enemy", 280LL, 288LL);
LODWORD(v10) = 255;
draw_text_color(screen, "p", 232LL, 304LL, 0LL, 255LL, v10);
draw_text(screen, "pause tower", 280LL, 304LL);
LODWORD(v11) = 255;
draw_text_color(screen, "space", 232LL, 320LL, 0LL, 255LL, v11);
draw_text(screen, "pause the game", 280LL, 320LL);
LODWORD(v12) = 255;
draw_text_color(screen, "esc", 232LL, 336LL, 0LL, 255LL, v12);
draw_text(screen, "quit to menu", 280LL, 336LL);
}
}
else if ( hoverchoice )
{
if ( hoverchoice == 1 )
{
SDL_UpperBlit(tut_upgrading, 0LL, screen, &tut_upgrading_rect);
draw_text(screen, "when a tower makes a killing blow", 200LL, 160LL);
draw_text(screen, "it earns experience. the yellow", 200LL, 176LL);
draw_text(screen, "bar indicates how far it is from", 200LL, 192LL);
draw_text(screen, "an upgrade. when a tower is fully", 200LL, 208LL);
draw_text(screen, "upgraded it will not gain more", 200LL, 224LL);
draw_text(screen, "experience. the killing blow goes", 200LL, 240LL);
draw_text(screen, "to the last upgradeable tower who", 200LL, 256LL);
draw_text(screen, "made a hit on the enemy. the", 200LL, 272LL);
draw_text(screen, "trick is to position the towers", 200LL, 288LL);
draw_text(screen, "in a way that makes sure that as little experience", 200LL, 304LL);
draw_text(screen, "as possible are wasted.", 200LL, 320LL);
}
}
else
{
SDL_UpperBlit(tut_basic, 0LL, screen, &tut_basic_rect);
draw_text(screen, "enemies will move down a road, if", 360LL, 160LL);
draw_text(screen, "they don't get killed before they", 360LL, 176LL);
draw_text(screen, "get to the end you lose a life.", 360LL, 192LL);
draw_text(screen, "the goal is to survive all the", 360LL, 208LL);
draw_text(screen, "upcoming waves of enemies. when", 360LL, 224LL);
draw_text(screen, "you kill an enemy, you recieve", 360LL, 240LL);
draw_text(screen, "money and points for each kill.", 360LL, 256LL);
draw_text(screen, "the amount of money you get only", 360LL, 272LL);
draw_text(screen, "depend on the enemy you kill.", 360LL, 288LL);
draw_text(screen, "the amount of points you get depend on how far the", 200LL, 304LL);
draw_text(screen, "enemy have travelled along the route. earlier kill", 200LL, 320LL);
draw_text(screen, "means more points.", 200LL, 336LL);
}
redraw = 0;
}
}

original_code:
void draw_tutorial(void) {
    int i;
    if ( sprites_loaded == 0 ) load_sprites();
    if ( redraw == 0 ) return;
    for (i=0;i<(sizeof(tutorials) / (sizeof((tutorials)[0])));i++)
        if (hoverchoice != i) draw_text(screen,tutorials[i],16,160+(i*16));
        else draw_text_color(screen,tutorials[i],16,160+(i*16),255,255,0);
    update_all();
    switch(hoverchoice) {
        case 0:
            SDL_UpperBlit(tut_basic,((void *)0),screen,&tut_basic_rect);
            draw_text(screen,"enemies will move down a road, if",360,160);
            draw_text(screen,"they don't get killed before they",360,176);
            draw_text(screen,"get to the end you lose a life.",360,192);
            draw_text(screen,"the goal is to survive all the",360,208);
            draw_text(screen,"upcoming waves of enemies. when",360,224);
            draw_text(screen,"you kill an enemy, you recieve",360,240);
            draw_text(screen,"money and points for each kill.",360,256);
            draw_text(screen,"the amount of money you get only",360,272);
            draw_text(screen,"depend on the enemy you kill.",360,288);
            draw_text(screen,"the amount of points you get depend on how far the",200,304);
            draw_text(screen,"enemy have travelled along the route. earlier kill",200,320);
            draw_text(screen,"means more points.",200,336);
        break;
        case 1:
            SDL_UpperBlit(tut_upgrading,((void *)0),screen,&tut_upgrading_rect);
            draw_text(screen,"when a tower makes a killing blow",200,160);
            draw_text(screen,"it earns experience. the yellow",200,176);
            draw_text(screen,"bar indicates how far it is from",200,192);
            draw_text(screen,"an upgrade. when a tower is fully",200,208);
            draw_text(screen,"upgraded it will not gain more",200,224);
            draw_text(screen,"experience. the killing blow goes",200,240);
            draw_text(screen,"to the last upgradeable tower who",200,256);
            draw_text(screen,"made a hit on the enemy. the",200,272);
            draw_text(screen,"trick is to position the towers",200,288);
            draw_text(screen,"in a way that makes sure that as little experience",200,304);
            draw_text(screen,"as possible are wasted.",200,320);
        break;
        case 2:
            draw_text(screen,"you can control how the towers determine which target",200,160);
            draw_text(screen,"to aim for. when you click a tower, a row of buttons",200,176);
            draw_text(screen,"will appear on the top of the screen. the buttons let",200,192);
            draw_text(screen,"you pick between 5 algorithms.",200,208);
            tower_dst.y = 232; tower_src.y = 24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy travelled the least",232,240);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy travelled the farthest",232,272);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy with most hp",232,304);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy with least hp",232,336);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot the fastest enemy",232,368);
        break;
        case 3:
                draw_text_color(screen,"1",232,160,0,255,255);
            draw_text(screen,"build pillbox",280,160);
                draw_text_color(screen,"2",232,176,0,255,255);
            draw_text(screen,"build artificial volcano",280,176);
                draw_text_color(screen,"3",232,192,0,255,255);
            draw_text(screen,"build freezer",280,192);
                draw_text_color(screen,"s",232,208,0,255,255);
            draw_text(screen,"sell tower",280,208);
                draw_text_color(screen,"q",232,224,0,255,255);
            draw_text(screen,"shoot enemy travelled the least",280,224);
                draw_text_color(screen,"w",232,240,0,255,255);
            draw_text(screen,"shoot enemy travelled the farthest",280,240);
                draw_text_color(screen,"e",232,256,0,255,255);
            draw_text(screen,"shoot enemy with most hp",280,256);
                draw_text_color(screen,"r",232,272,0,255,255);
            draw_text(screen,"shoot enemy with least hp",280,272);
                draw_text_color(screen,"t",232,288,0,255,255);
            draw_text(screen,"shoot the fastest enemy",280,288);
                draw_text_color(screen,"p",232,304,0,255,255);
            draw_text(screen,"pause tower",280,304);
                draw_text_color(screen,"space",232,320,0,255,255);
            draw_text(screen,"pause the game",280,320);
                draw_text_color(screen,"esc",232,336,0,255,255);
            draw_text(screen,"quit to menu",280,336);
        break;
    }
    redraw = 0;
    return;
}

canonical_original_code:
void draw_tutorial() {
    int i;
    if ( sprites_loaded == 0 ) load_sprites();
    if ( redraw == 0 ) return;
    for (i=0;i<(sizeof(tutorials) / (sizeof((tutorials)[0])));i++)
        if (hoverchoice != i) draw_text(screen,tutorials[i],16,160+(i*16));
        else draw_text_color(screen,tutorials[i],16,160+(i*16),255,255,0);
    update_all();
    switch(hoverchoice) {
        case 0:
            SDL_UpperBlit(tut_basic,((void *)0),screen,&tut_basic_rect);
            draw_text(screen,"enemies will move down a road, if",360,160);
            draw_text(screen,"they don't get killed before they",360,176);
            draw_text(screen,"get to the end you lose a life.",360,192);
            draw_text(screen,"the goal is to survive all the",360,208);
            draw_text(screen,"upcoming waves of enemies. when",360,224);
            draw_text(screen,"you kill an enemy, you recieve",360,240);
            draw_text(screen,"money and points for each kill.",360,256);
            draw_text(screen,"the amount of money you get only",360,272);
            draw_text(screen,"depend on the enemy you kill.",360,288);
            draw_text(screen,"the amount of points you get depend on how far the",200,304);
            draw_text(screen,"enemy have travelled along the route. earlier kill",200,320);
            draw_text(screen,"means more points.",200,336);
        break;
        case 1:
            SDL_UpperBlit(tut_upgrading,((void *)0),screen,&tut_upgrading_rect);
            draw_text(screen,"when a tower makes a killing blow",200,160);
            draw_text(screen,"it earns experience. the yellow",200,176);
            draw_text(screen,"bar indicates how far it is from",200,192);
            draw_text(screen,"an upgrade. when a tower is fully",200,208);
            draw_text(screen,"upgraded it will not gain more",200,224);
            draw_text(screen,"experience. the killing blow goes",200,240);
            draw_text(screen,"to the last upgradeable tower who",200,256);
            draw_text(screen,"made a hit on the enemy. the",200,272);
            draw_text(screen,"trick is to position the towers",200,288);
            draw_text(screen,"in a way that makes sure that as little experience",200,304);
            draw_text(screen,"as possible are wasted.",200,320);
        break;
        case 2:
            draw_text(screen,"you can control how the towers determine which target",200,160);
            draw_text(screen,"to aim for. when you click a tower, a row of buttons",200,176);
            draw_text(screen,"will appear on the top of the screen. the buttons let",200,192);
            draw_text(screen,"you pick between 5 algorithms.",200,208);
            tower_dst.y = 232; tower_src.y = 24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy travelled the least",232,240);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy travelled the farthest",232,272);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy with most hp",232,304);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot enemy with least hp",232,336);
            tower_dst.y = tower_dst.y+32; tower_src.y = tower_src.y +24;
            SDL_UpperBlit(buttonsurface2,&tower_src,screen,&tower_dst);
            draw_text(screen,"shoot the fastest enemy",232,368);
        break;
        case 3:
                draw_text_color(screen,"1",232,160,0,255,255);
            draw_text(screen,"build pillbox",280,160);
                draw_text_color(screen,"2",232,176,0,255,255);
            draw_text(screen,"build artificial volcano",280,176);
                draw_text_color(screen,"3",232,192,0,255,255);
            draw_text(screen,"build freezer",280,192);
                draw_text_color(screen,"s",232,208,0,255,255);
            draw_text(screen,"sell tower",280,208);
                draw_text_color(screen,"q",232,224,0,255,255);
            draw_text(screen,"shoot enemy travelled the least",280,224);
                draw_text_color(screen,"w",232,240,0,255,255);
            draw_text(screen,"shoot enemy travelled the farthest",280,240);
                draw_text_color(screen,"e",232,256,0,255,255);
            draw_text(screen,"shoot enemy with most hp",280,256);
                draw_text_color(screen,"r",232,272,0,255,255);
            draw_text(screen,"shoot enemy with least hp",280,272);
                draw_text_color(screen,"t",232,288,0,255,255);
            draw_text(screen,"shoot the fastest enemy",280,288);
                draw_text_color(screen,"p",232,304,0,255,255);
            draw_text(screen,"pause tower",280,304);
                draw_text_color(screen,"space",232,320,0,255,255);
            draw_text(screen,"pause the game",280,320);
                draw_text_color(screen,"esc",232,336,0,255,255);
            draw_text(screen,"quit to menu",280,336);
        break;
    }
    redraw = 0;
    return;
}

variable_types: i int


decompiled_code:
void __fastcall update_tutorial_selection(int a1, int a2)
{
int v2; // eax
int v3; // esi

if ( (unsigned int)(a1 - 16) <= 0xA0 && (unsigned int)(a2 - 160) <= 0x3F )
{
v2 = a2 - 145;
v3 = a2 - 160;
if ( v3 < 0 )
v3 = v2;
hoverchoice = v3 >> 4;
}
redraw = 1;
}

canonical_decompiled_code:
void __fastcall func3(int a1, int a2)
{
int v2; // eax
int v3; // esi

if ( (unsigned int)(a1 - 16) <= 0xA0 && (unsigned int)(a2 - 160) <= 0x3F )
{
v2 = a2 - 145;
v3 = a2 - 160;
if ( v3 < 0 )
v3 = v2;
hoverchoice = v3 >> 4;
}
redraw = 1;
}

original_code:
void update_tutorial_selection(int x, int y) {
    if ( x >= 16 && x <= 176 && y >= 160 && y < (160+(16*4)) )
        hoverchoice = (y-160)/16;
    redraw = 1;
    return;
}


decompiled_code:
__int64 __fastcall update_cursor(int a1, int a2)
{
int v3; // edi
__int64 v4; // rdi

updaterect((unsigned int)cell_x, (unsigned int)cell_y);
v3 = a1 + 31;
if ( a1 >= 0 )
v3 = a1;
v4 = (unsigned int)(v3 >> 5);
cell_x = v4;
cell_y = a2 / 32;
return updaterect(v4, (unsigned int)(a2 / 32));
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v3; // edi
__int64 v4; // rdi

updaterect((unsigned int)cell_x, (unsigned int)cell_y);
v3 = a1 + 31;
if ( a1 >= 0 )
v3 = a1;
v4 = (unsigned int)(v3 >> 5);
cell_x = v4;
cell_y = a2 / 32;
return updaterect(v4, (unsigned int)(a2 / 32));
}

original_code:
void update_cursor(int x, int y) {
    updaterect(cell_x,cell_y);
    mouse_x = x;
    mouse_y = y;
    cell_x = x / 32;
    cell_y = y / 32;
    updaterect(cell_x,cell_y);
}


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

if ( a2 > 14 || a1 > 19 )
result = 0xFFFFFFFFLL;
else
result = levels[300 * currentlevel + 20 * a2 + a1] == 2;
return result;
}

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

if ( a2 > 14 || a1 > 19 )
result = 0xFFFFFFFFLL;
else
result = levels[300 * currentlevel + 20 * a2 + a1] == 2;
return result;
}

original_code:
int is_path(int x, int y) {
    if ( x > 19 ) return -1;
    if ( y > 14 ) return -1;
    if ( levels[currentlevel][y][x] == 2 ) return 1;
    return 0;
}


decompiled_code:
__int64 __fastcall update_tooltip(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx

for ( result = 0LL; result != 7; ++result )
{
v3 = button_rects2[4 * result];
if ( v3 < a1 && (unsigned __int16)word_5C4[4 * result] + v3 > a1 )
{
v4 = word_5C2[4 * result];
if ( v4 < a2 && (unsigned __int16)word_5C6[4 * result] + v4 > a2 )
{
button2tooltip = result;
return result;
}
}
}
button2tooltip = -1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // edx

for ( result = 0LL; result != 7; ++result )
{
v3 = button_rects2[4 * result];
if ( v3 < a1 && (unsigned __int16)word_5C4[4 * result] + v3 > a1 )
{
v4 = word_5C2[4 * result];
if ( v4 < a2 && (unsigned __int16)word_5C6[4 * result] + v4 > a2 )
{
button2tooltip = result;
return result;
}
}
}
button2tooltip = -1;
return result;
}

original_code:
void update_tooltip(int x, int y) {
    int i;
    for (i=0;i<button2_count;i++) {
        if ( x > button_rects2[i].x && x < (button_rects2[i].x+button_rects2[i].w) &&
             y > button_rects2[i].y && y < (button_rects2[i].y+button_rects2[i].h) ) {
            button2tooltip = i;
            return;
        }
    }
    button2tooltip = -1;
}


decompiled_code:
__int64 init_buttons()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 result; // rax

v0 = SDL_RWFromMem(&binary_buttonbar_bmp_start, &binary_buttonbar_bmp_end - &binary_buttonbar_bmp_start);
buttonsurface = SDL_LoadBMP_RW(v0, 0LL);
v1 = SDL_RWFromMem(&binary_buttonbar2_bmp_start, &binary_buttonbar2_bmp_end - &binary_buttonbar2_bmp_start);
result = SDL_LoadBMP_RW(v1, 0LL);
buttonsurface2 = result;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 result; // rax

v0 = SDL_RWFromMem(&binary_buttonbar_bmp_start, &binary_buttonbar_bmp_end - &binary_buttonbar_bmp_start);
buttonsurface = SDL_LoadBMP_RW(v0, 0LL);
v1 = SDL_RWFromMem(&binary_buttonbar2_bmp_start, &binary_buttonbar2_bmp_end - &binary_buttonbar2_bmp_start);
result = SDL_LoadBMP_RW(v1, 0LL);
buttonsurface2 = result;
return result;
}

original_code:
void init_buttons(void) {
    buttonsurface = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_buttonbar_bmp_start),(&_binary_buttonbar_bmp_end - &_binary_buttonbar_bmp_start)),0);
    buttonsurface2 = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_buttonbar2_bmp_start),(&_binary_buttonbar2_bmp_end - &_binary_buttonbar2_bmp_start)),0);
}

canonical_original_code:
void init_buttons() {
    buttonsurface = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_buttonbar_bmp_start),(&_binary_buttonbar_bmp_end - &_binary_buttonbar_bmp_start)),0);
    buttonsurface2 = SDL_LoadBMP_RW(SDL_RWFromMem((&_binary_buttonbar2_bmp_start),(&_binary_buttonbar2_bmp_end - &_binary_buttonbar2_bmp_start)),0);
}


decompiled_code:
__int64 __fastcall press_buttonnumber(int a1)
{
button_pressed[a1 - 1] = 1;
towerbutton = 3 * (a1 - 1);
sprintf(&costtext, "%6d", tower_definitions[51 * a1 - 43]);
if ( a1 != 1 && (button_pressed[0] = 0, a1 == 2) || (dword_5A4 = 0, a1 != 3) )
dword_5A8 = 0;
return draw_buttons(screen);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
button_pressed[a1 - 1] = 1;
towerbutton = 3 * (a1 - 1);
sprintf(&costtext, "%6d", tower_definitions[51 * a1 - 43]);
if ( a1 != 1 && (button_pressed[0] = 0, a1 == 2) || (dword_5A4 = 0, a1 != 3) )
dword_5A8 = 0;
return func2(screen);
}

original_code:
void press_buttonnumber(int i) {
    int n;
    button_pressed[i-1] = 1;
    towerbutton = ((i-1)*3);
    sprintf(costtext, "%6d", tower_definitions[towerbutton].price);
    for (n=0;n<button_count;n++) { if (n != (i-1) ) button_pressed[n] = 0; }
    draw_buttons(screen);
}

variable_types: n int


decompiled_code:
__int64 __fastcall press_button(int a1, int a2)
{
__int64 i; // rax
int v3; // ebx
int v4; // ecx
int v5; // edx
__int64 result; // rax
int v7; // ecx
int v8; // edx

for ( i = 0LL; i != 3; ++i )
{
v3 = i;
v4 = button_rects[4 * i];
if ( v4 + (unsigned __int16)word_604[4 * i] >= a1 && v4 <= a1 )
{
v5 = word_602[4 * i];
if ( v5 <= a2 && (unsigned __int16)word_606[4 * i] + v5 >= a2 )
{
button_pressed[(int)i] = 1;
towerbutton = 3 * i;
sprintf(&costtext, "%6d", tower_definitions[51 * (_DWORD)i + 8]);
if ( v3 && (button_pressed[0] = 0, v3 == 1) || (dword_5A4 = 0, v3 != 2) )
dword_5A8 = 0;
return draw_buttons(screen);
}
}
}
result = 0LL;
while ( 1 )
{
v7 = button_rects2[4 * result];
if ( v7 + (unsigned __int16)word_5C4[4 * result] >= a1 && v7 <= a1 )
{
v8 = word_5C2[4 * result];
if ( v8 <= a2 && (unsigned __int16)word_5C6[4 * result] + v8 >= a2 )
break;
}
if ( ++result == 7 )
return result;
}
if ( !(_DWORD)result )
return sell_tower(selected_tower);
if ( (_DWORD)result == 6 )
return toggle_shooting(selected_tower);
return tower_algorithm(selected_tower, (unsigned int)result);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
__int64 i; // rax
int v3; // ebx
int v4; // ecx
int v5; // edx
__int64 result; // rax
int v7; // ecx
int v8; // edx

for ( i = 0LL; i != 3; ++i )
{
v3 = i;
v4 = button_rects[4 * i];
if ( v4 + (unsigned __int16)word_604[4 * i] >= a1 && v4 <= a1 )
{
v5 = word_602[4 * i];
if ( v5 <= a2 && (unsigned __int16)word_606[4 * i] + v5 >= a2 )
{
button_pressed[(int)i] = 1;
towerbutton = 3 * i;
sprintf(&costtext, "%6d", tower_definitions[51 * (_DWORD)i + 8]);
if ( v3 && (button_pressed[0] = 0, v3 == 1) || (dword_5A4 = 0, v3 != 2) )
dword_5A8 = 0;
return func2(screen);
}
}
}
result = 0LL;
while ( 1 )
{
v7 = button_rects2[4 * result];
if ( v7 + (unsigned __int16)word_5C4[4 * result] >= a1 && v7 <= a1 )
{
v8 = word_5C2[4 * result];
if ( v8 <= a2 && (unsigned __int16)word_5C6[4 * result] + v8 >= a2 )
break;
}
if ( ++result == 7 )
return result;
}
if ( !(_DWORD)result )
return sell_tower(selected_tower);
if ( (_DWORD)result == 6 )
return toggle_shooting(selected_tower);
return tower_algorithm(selected_tower, (unsigned int)result);
}

original_code:
void press_button(int x, int y) {
    int i, n;
    for (i=0;i<button_count;i++) {
        if ( x <= (button_rects[i].x + button_rects[i].w) && x >= button_rects[i].x && y >= button_rects[i].y && y <= (button_rects[i].y + button_rects[i].h) ) {
            button_pressed[i] = 1;
            towerbutton = (i*3);
            sprintf(costtext, "%6d", tower_definitions[(i*3)].price);
            for (n=0;n<button_count;n++) { if (n != i ) button_pressed[n] = 0; }
            draw_buttons(screen);
            return;
        }
    }
    for (i=0;i<button2_count;i++) {
        if ( x <= (button_rects2[i].x + button_rects2[i].w) && x >= button_rects2[i].x && y >= button_rects2[i].y && y <= (button_rects2[i].y + button_rects2[i].h) ) {
            if ( i == 0 ) sell_tower(selected_tower);
            else if ( i == 6 ) toggle_shooting(selected_tower);
            else tower_algorithm(selected_tower, i);
            return;
        }
    }
}

canonical_original_code:
void press_button(int x, int y) {
    int i; int n;
    for (i=0;i<button_count;i++) {
        if ( x <= (button_rects[i].x + button_rects[i].w) && x >= button_rects[i].x && y >= button_rects[i].y && y <= (button_rects[i].y + button_rects[i].h) ) {
            button_pressed[i] = 1;
            towerbutton = (i*3);
            sprintf(costtext, "%6d", tower_definitions[(i*3)].price);
            for (n=0;n<button_count;n++) { if (n != i ) button_pressed[n] = 0; }
            draw_buttons(screen);
            return;
        }
    }
    for (i=0;i<button2_count;i++) {
        if ( x <= (button_rects2[i].x + button_rects2[i].w) && x >= button_rects2[i].x && y >= button_rects2[i].y && y <= (button_rects2[i].y + button_rects2[i].h) ) {
            if ( i == 0 ) sell_tower(selected_tower);
            else if ( i == 6 ) toggle_shooting(selected_tower);
            else tower_algorithm(selected_tower, i);
            return;
        }
    }
}


decompiled_code:
__int64 show_credits()
{
current_screen = 4;
return update_all();
}

canonical_decompiled_code:
__int64 func0()
{
current_screen = 4;
return update_all();
}

original_code:
void show_credits(void) {
    current_screen = 4;
    update_all();
}

canonical_original_code:
void show_credits() {
    current_screen = 4;
    update_all();
}


decompiled_code:
__int64 draw_credits()
{
char **v0; // r12
unsigned int i; // ebx
__int64 result; // rax

v0 = &credits;
for ( i = 200; i != 392; i += 16 )
result = draw_text(screen, *v0++, 200LL, i);
return result;
}

canonical_decompiled_code:
__int64 func1()
{
char **v0; // r12
unsigned int i; // ebx
__int64 result; // rax

v0 = &credits;
for ( i = 200; i != 392; i += 16 )
result = draw_text(screen, *v0++, 200LL, i);
return result;
}

original_code:
void draw_credits(void) {
    int i;
    for (i=0;i<(sizeof(credits) / (sizeof((credits)[0])));i++) {
        draw_text(screen,credits[i],200,(200+(i*16)));
    }
}

canonical_original_code:
void draw_credits() {
    int i;
    for (i=0;i<(sizeof(credits) / (sizeof((credits)[0])));i++) {
        draw_text(screen,credits[i],200,(200+(i*16)));
    }
}


decompiled_code:
char *init_gfx_charmap()
{
int i; // ebx
char *v1; // r12
__int16 v2; // r14
char *v3; // r13
char *result; // rax
char *v5; // [rsp+0h] [rbp-50h]
__int16 v6; // [rsp+Ah] [rbp-46h]
unsigned int v7; // [rsp+Ch] [rbp-44h]
__int16 v8; // [rsp+18h] [rbp-38h] BYREF
__int16 v9; // [rsp+1Ah] [rbp-36h]
__int16 v10; // [rsp+1Ch] [rbp-34h]
__int16 v11; // [rsp+1Eh] [rbp-32h]

v8 = 0;
v9 = 0;
v10 = 1;
v11 = 1;
charmapsurface = SDL_CreateRGBSurface(0LL, 336LL, 8LL, 8LL, 255LL, 255LL, 255LL, 0LL);
v7 = SDL_MapRGB(*(_QWORD *)(charmapsurface + 8), 255LL, 255LL, 255LL);
v5 = (char *)&unk_4A0;
v6 = 0;
do
{
v3 = v5 - 32;
v2 = v6;
do
{
v1 = v3;
for ( i = 0; i != 8; ++i )
{
if ( *(_DWORD *)v1 == 1 )
{
v8 = v2;
v9 = i;
SDL_FillRect(charmapsurface, &v8, v7);
}
v1 += 32;
}
++v2;
v3 += 4;
}
while ( v3 != v5 );
v5 += 256;
result = v5;
v6 += 8;
}
while ( v5 != (char *)&unk_2EA0 );
++charmap_inited;
return result;
}

canonical_decompiled_code:
char *func0()
{
int i; // ebx
char *v1; // r12
__int16 v2; // r14
char *v3; // r13
char *result; // rax
char *v5; // [rsp+0h] [rbp-50h]
__int16 v6; // [rsp+Ah] [rbp-46h]
unsigned int v7; // [rsp+Ch] [rbp-44h]
__int16 v8; // [rsp+18h] [rbp-38h] BYREF
__int16 v9; // [rsp+1Ah] [rbp-36h]
__int16 v10; // [rsp+1Ch] [rbp-34h]
__int16 v11; // [rsp+1Eh] [rbp-32h]

v8 = 0;
v9 = 0;
v10 = 1;
v11 = 1;
charmapsurface = SDL_CreateRGBSurface(0LL, 336LL, 8LL, 8LL, 255LL, 255LL, 255LL, 0LL);
v7 = SDL_MapRGB(*(_QWORD *)(charmapsurface + 8), 255LL, 255LL, 255LL);
v5 = (char *)&unk_4A0;
v6 = 0;
do
{
v3 = v5 - 32;
v2 = v6;
do
{
v1 = v3;
for ( i = 0; i != 8; ++i )
{
if ( *(_DWORD *)v1 == 1 )
{
v8 = v2;
v9 = i;
SDL_FillRect(charmapsurface, &v8, v7);
}
v1 += 32;
}
++v2;
v3 += 4;
}
while ( v3 != v5 );
v5 += 256;
result = v5;
v6 += 8;
}
while ( v5 != (char *)&unk_2EA0 );
++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


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

canonical_decompiled_code:
__int64 func2()
{
render_t = 24;
dword_164 = 3;
SDL_AddTimer(16LL, timedrenderevent, &render_t);
report_fps_t = 24;
dword_144 = 1;
SDL_AddTimer(1000LL, timeduserevent, &report_fps_t);
game_cycle_t = 24;
dword_124 = 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);
}


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

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

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

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 i; // ebx
__int64 result; // rax
__int64 v3; // rcx

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

canonical_decompiled_code:
__int64 func0()
{
char *v0; // r12
int i; // ebx
__int64 result; // rax
__int64 v3; // rcx

v0 = options;
for ( i = 0; i != 5; ++i )
{
v3 = (unsigned int)(16 * i + 200);
if ( selected == i )
result = draw_text_color(screen, v0, 400LL, v3, 255LL, 255LL, 0LL);
else
result = draw_text_color(screen, v0, 400LL, v3, 255LL, 255LL, 255LL);
v0 += 12;
}
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: ypos int


decompiled_code:
__int64 click_menu()
{
unsigned int v0; // ebx

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

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx

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

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


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

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

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

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


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


repo: kwingmei/softTV

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


main

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

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

canonical_original_code:
int main()
{
 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; }


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


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


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)
{
int v2; // edx
__int64 v3; // rdi
__int64 v4; // rax
unsigned int v5; // ecx

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

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

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

original_code:
int 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)
{
int v2; // edx
__int64 v3; // rdi
__int64 v4; // rax
unsigned int v5; // ecx

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

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

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

original_code:
int 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
__int64 v3; // r12

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

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

result = func5(a1, a2);
if ( (_DWORD)result == -1 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( (unsigned int)func4(v3, a2) == -1 )
func6(v3, a2);
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(_QWORD *a1, char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, char *a2)
{
_QWORD *v2; // rbx
__int64 v3; // rbp

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

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)
{
_QWORD *v2; // rbx
__int64 result; // rax

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

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

v2 = *(_QWORD **)(a1 + 8);
if ( v2 || (fatal("Empty contour."), v2 = *(_QWORD **)(a1 + 8), (result = (__int64)v2) != 0) )
{
while ( 1 )
{
result = func9(v2, a2);
if ( result )
break;
v2 = (_QWORD *)v2[1];
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; }