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

if ( a1[4] < a2 )
result = 0LL;
else
result = *(_QWORD *)&a1[2 * (a2 >> a1[1]) + 6] + a1[3] * (a2 & *a1);
return result;
}

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

if ( a1[4] < a2 )
result = 0LL;
else
result = *(_QWORD *)&a1[2 * (a2 >> a1[1]) + 6] + a1[3] * (a2 & *a1);
return result;
}

variable_types: struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; } *

variable_types:
index
unsigned int


repo: kurt-gehlen/Testcode

original_code:
int
SCH_init( SC_Hashtable * ht, int tablesize, int objectsize, SegArray * array, HASHFUNC hash, COMPFUNC comp, ALLOCFUNC alloc, FREEFUNC dealloc, DELFUNC del )
{
 if ( (ht->table = (int *)malloc( tablesize * sizeof(int *) )) )
 {
  ht->tablesize = tablesize;
  ht->array = array;
  ht->objsize = objectsize;
  ht->count = 0;
  ht->maxdepth = 0;
  ht->hash = hash;
  ht->comp = comp;
  ht->del = del;
  ht->alloc = alloc;
  ht->dealloc = dealloc;
  int i;
  for ( i = 0; i < tablesize; ++i )
   ht->table[i] = -1;
  return 0;
 }
 return -1;
}

canonical_original_code:
int SCH_init(struct SC_Hashtable *ht, int tablesize, int objectsize, struct SegArray *array, unsigned long (*hash)(void *), int (*comp)(void *, void *), int (*alloc)(), void (*dealloc)(int), void (*del)(void *))
{
 if ( (ht->table = (int *)malloc( tablesize * sizeof(int *) )) )
 {
  ht->tablesize = tablesize;
  ht->array = array;
  ht->objsize = objectsize;
  ht->count = 0;
  ht->maxdepth = 0;
  ht->hash = hash;
  ht->comp = comp;
  ht->del = del;
  ht->alloc = alloc;
  ht->dealloc = dealloc;
  int i;
  for ( i = 0; i < tablesize; ++i )
   ht->table[i] = -1;
  return 0;
 }
 return -1;
}

variable_types: struct SC_Hashtable { int tablesize; int objsize; int count; int *table; struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; } *array; int maxdepth; unsigned long (*hash)(void *); int (*comp)(void *, void *); void (*del)(void *); int (*alloc)(); void (*dealloc)(int); } *

variable_types: tablesize int

variable_types: objectsize int

variable_types:
array
struct SegArray *

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

variable_types:
comp
int (*)(void *, void *)

variable_types:
alloc
int (*)()

variable_types:
dealloc
void (*)(int)

variable_types:
del
void (*)(void *)

variable_types: i int

return_type: int

user_defined_types: struct SC_Hashtable { int tablesize; int objsize; int count; int *table; struct SegArray *array; int maxdepth; unsigned long (*hash)(void *); int (*comp)(void *, void *); void (*del)(void *); int (*alloc)(); void (*dealloc)(int); }


decompiled_code:
void __fastcall SCH_delete(__int64 a1)
{
int v2; // eax
_DWORD *v3; // rdi
__int64 v4; // r12
unsigned int v5; // esi
unsigned int *v6; // rbx
void (__fastcall *v7)(unsigned int *); // rax

v2 = *(_DWORD *)a1;
v3 = *(_DWORD **)(a1 + 16);
if ( v2 > 0 )
{
v4 = 0LL;
do
{
v5 = v3[v4];
if ( v5 != -1 )
{
do
{
v6 = (unsigned int *)SA_atIndex(*(_DWORD **)(a1 + 24), v5);
v7 = *(void (__fastcall **)(unsigned int *))(a1 + 56);
if ( v7 )
v7(v6 + 1);
v5 = *v6;
}
while ( *v6 != -1 );
v3 = *(_DWORD **)(a1 + 16);
}
++v4;
}
while ( *(_DWORD *)a1 > (int)v4 );
}
if ( v3 )
free(v3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
int v2; // eax
_DWORD *v3; // rdi
__int64 v4; // r12
unsigned int v5; // esi
unsigned int *v6; // rbx
void (__fastcall *v7)(unsigned int *); // rax

v2 = *(_DWORD *)a1;
v3 = *(_DWORD **)(a1 + 16);
if ( v2 > 0 )
{
v4 = 0LL;
do
{
v5 = v3[v4];
if ( v5 != -1 )
{
do
{
v6 = (unsigned int *)func0(*(_DWORD **)(a1 + 24), v5);
v7 = *(void (__fastcall **)(unsigned int *))(a1 + 56);
if ( v7 )
v7(v6 + 1);
v5 = *v6;
}
while ( *v6 != -1 );
v3 = *(_DWORD **)(a1 + 16);
}
++v4;
}
while ( *(_DWORD *)a1 > (int)v4 );
}
if ( v3 )
free(v3);
}

original_code:
void
SCH_delete( SC_Hashtable * ht )
{
 int i;
 for ( i = 0; i < ht->tablesize; ++i )
 {
  int index = ht->table[i];
  while ( index != -1 )
  {
   int * object = SA_atIndex( ht->array, index );
   if( ht->del )
    ht->del( object + 1 );
   index = *object;
  }
 }
 if ( ht->table )
  free(ht->table);
}

canonical_original_code:
void SCH_delete(struct SC_Hashtable *ht)
{
 int i;
 for ( i = 0; i < ht->tablesize; ++i )
 {
  int index = ht->table[i];
  while ( index != -1 )
  {
   int *object = SA_atIndex( ht->array, index );
   if( ht->del )
    ht->del( object + 1 );
   index = *object;
  }
 }
 if ( ht->table )
  free(ht->table);
}

variable_types: index int

variable_types:
object
int *

return_type: void

user_defined_types: struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; }


decompiled_code:
unsigned int *__fastcall SCH_find(int *a1, __int64 a2)
{
unsigned __int64 v2; // rax
unsigned int *v3; // rbx
int v4; // eax
unsigned int *result; // rax

v2 = (*((__int64 (__fastcall **)(__int64))a1 + 5))(a2);
v3 = (unsigned int *)SA_atIndex(*((_DWORD **)a1 + 3), *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * (v2 % *a1)));
if ( !v3 )
goto LABEL_7;
while ( 1 )
{
v4 = (*((__int64 (__fastcall **)(__int64, unsigned int *))a1 + 6))(a2, v3 + 1);
if ( v4 >= 0 )
break;
v3 = (unsigned int *)SA_atIndex(*((_DWORD **)a1 + 3), *v3);
if ( !v3 )
goto LABEL_7;
}
if ( v4 )
LABEL_7:
result = 0LL;
else
result = v3 + 1;
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func3(int *a1, __int64 a2)
{
unsigned __int64 v2; // rax
unsigned int *v3; // rbx
int v4; // eax
unsigned int *result; // rax

v2 = (*((__int64 (__fastcall **)(__int64))a1 + 5))(a2);
v3 = (unsigned int *)func0(*((_DWORD **)a1 + 3), *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * (v2 % *a1)));
if ( !v3 )
goto LABEL_7;
while ( 1 )
{
v4 = (*((__int64 (__fastcall **)(__int64, unsigned int *))a1 + 6))(a2, v3 + 1);
if ( v4 >= 0 )
break;
v3 = (unsigned int *)func0(*((_DWORD **)a1 + 3), *v3);
if ( !v3 )
goto LABEL_7;
}
if ( v4 )
LABEL_7:
result = 0LL;
else
result = v3 + 1;
return result;
}

original_code:
void *
SCH_find( SC_Hashtable * ht, void * item )
{
 unsigned long hash_value = ht->hash( item );
 hash_value %= ht->tablesize;
 int * node;
 int v;
 for ( node = SA_atIndex(ht->array,ht->table[hash_value]); node && (v = ht->comp(item,node + 1)) < 0; node = SA_atIndex(ht->array,*node) )
  ;
 if ( node && v == 0 )
  return node + 1;
 return 0;
}

canonical_original_code:
void *SCH_find(struct SC_Hashtable *ht, void *item)
{
 unsigned long hash_value = ht->hash( item );
 hash_value %= ht->tablesize;
 int *node;
 int v;
 for ( node = SA_atIndex(ht->array,ht->table[hash_value]); node && (v = ht->comp(item,node + 1)) < 0; node = SA_atIndex(ht->array,*node) )
  ;
 if ( node && v == 0 )
  return node + 1;
 return 0;
}

variable_types:
item
void *

variable_types:
node
int *

variable_types: v int

return_type: void *


decompiled_code:
__int64 __fastcall SCH_remove(int *a1, __int64 a2, void *a3)
{
unsigned int *v4; // r14
__int64 v5; // rax
const void *v6; // r15
unsigned int *v7; // rbx
int v8; // eax
void (__fastcall *v9)(const void *); // rax
unsigned int v10; // er12
__int64 result; // rax

v4 = (unsigned int *)(*((_QWORD *)a1 + 2)
+ 4 * ((*((__int64 (__fastcall **)(__int64))a1 + 5))(a2) % (unsigned __int64)*a1));
v5 = SA_atIndex(*((_DWORD **)a1 + 3), *v4);
if ( !v5 )
return 0LL;
while ( 1 )
{
v6 = (const void *)(v5 + 4);
v7 = (unsigned int *)v5;
v8 = (*((__int64 (__fastcall **)(__int64, __int64))a1 + 6))(a2, v5 + 4);
if ( v8 >= 0 )
break;
v4 = v7;
v5 = SA_atIndex(*((_DWORD **)a1 + 3), *v7);
if ( !v5 )
return 0LL;
}
if ( v8 )
return 0LL;
if ( a3 )
memcpy(a3, v6, a1[1]);
v9 = (void (__fastcall *)(const void *))*((_QWORD *)a1 + 7);
if ( v9 )
v9(v6);
v10 = *v7;
*v7 = -1;
(*((void (__fastcall **)(_QWORD))a1 + 9))(*v4);
*v4 = v10;
result = 1LL;
--a1[2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1, __int64 a2, void *a3)
{
unsigned int *v4; // r14
__int64 v5; // rax
const void *v6; // r15
unsigned int *v7; // rbx
int v8; // eax
void (__fastcall *v9)(const void *); // rax
unsigned int v10; // er12
__int64 result; // rax

v4 = (unsigned int *)(*((_QWORD *)a1 + 2)
+ 4 * ((*((__int64 (__fastcall **)(__int64))a1 + 5))(a2) % (unsigned __int64)*a1));
v5 = func0(*((_DWORD **)a1 + 3), *v4);
if ( !v5 )
return 0LL;
while ( 1 )
{
v6 = (const void *)(v5 + 4);
v7 = (unsigned int *)v5;
v8 = (*((__int64 (__fastcall **)(__int64, __int64))a1 + 6))(a2, v5 + 4);
if ( v8 >= 0 )
break;
v4 = v7;
v5 = func0(*((_DWORD **)a1 + 3), *v7);
if ( !v5 )
return 0LL;
}
if ( v8 )
return 0LL;
if ( a3 )
memcpy(a3, v6, a1[1]);
v9 = (void (__fastcall *)(const void *))*((_QWORD *)a1 + 7);
if ( v9 )
v9(v6);
v10 = *v7;
*v7 = -1;
(*((void (__fastcall **)(_QWORD))a1 + 9))(*v4);
*v4 = v10;
result = 1LL;
--a1[2];
return result;
}

original_code:
int
SCH_remove( SC_Hashtable * ht, void * item, void * copy )
{
 unsigned long hash_value = ht->hash( item );
 hash_value %= ht->tablesize;
 int v;
 int * prev = &ht->table[hash_value];
 int * node;
 for ( node = SA_atIndex(ht->array,ht->table[hash_value]); node && (v = ht->comp(item,node + 1)) < 0; node = SA_atIndex(ht->array,*node) )
  prev = node;
 if ( !node || v != 0 )
  return 0;
 if ( copy )
  memcpy( copy, node + 1, ht->objsize );
 if ( ht->del )
  ht->del( node + 1 );
 int next = *node;
 *node = -1;
 ht->dealloc( *prev );
 *prev = next;
 ht->count--;
 return 1;
}

canonical_original_code:
int SCH_remove(struct SC_Hashtable *ht, void *item, void *copy)
{
 unsigned long hash_value = ht->hash( item );
 hash_value %= ht->tablesize;
 int v;
 int *prev = &ht->table[hash_value];
 int *node;
 for ( node = SA_atIndex(ht->array,ht->table[hash_value]); node && (v = ht->comp(item,node + 1)) < 0; node = SA_atIndex(ht->array,*node) )
  prev = node;
 if ( !node || v != 0 )
  return 0;
 if ( copy )
  memcpy( copy, node + 1, ht->objsize );
 if ( ht->del )
  ht->del( node + 1 );
 int next = *node;
 *node = -1;
 ht->dealloc( *prev );
 *prev = next;
 ht->count--;
 return 1;
}

variable_types:
copy
void *

variable_types:
prev
int *

variable_types: next int


decompiled_code:
void __fastcall SCH_iterate(int *a1, void (__fastcall *a2)(unsigned int *, _QWORD))
{
__int64 v2; // r14
int v3; // ebp
unsigned int *i; // r15
__int64 v5; // [rsp+8h] [rbp-40h]

if ( *a1 > 0 )
{
v2 = 0LL;
v5 = *a1;
do
{
v3 = 0;
for ( i = (unsigned int *)SA_atIndex(*((_DWORD **)a1 + 3), *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * v2));
i;
i = (unsigned int *)SA_atIndex(*((_DWORD **)a1 + 3), *i) )
{
++v3;
a2(i + 1, (unsigned int)v2);
}
if ( a1[8] < v3 )
printf("bad cnt %d at %d\n", (unsigned int)v3, (unsigned int)v2);
++v2;
}
while ( v5 != v2 );
}
}

canonical_decompiled_code:
void __fastcall func5(int *a1, void (__fastcall *a2)(unsigned int *, _QWORD))
{
__int64 v2; // r14
int v3; // ebp
unsigned int *i; // r15
__int64 v5; // [rsp+8h] [rbp-40h]

if ( *a1 > 0 )
{
v2 = 0LL;
v5 = *a1;
do
{
v3 = 0;
for ( i = (unsigned int *)func0(*((_DWORD **)a1 + 3), *(_DWORD *)(*((_QWORD *)a1 + 2) + 4 * v2));
i;
i = (unsigned int *)func0(*((_DWORD **)a1 + 3), *i) )
{
++v3;
a2(i + 1, (unsigned int)v2);
}
if ( a1[8] < v3 )
printf("bad cnt %d at %d\n", (unsigned int)v3, (unsigned int)v2);
++v2;
}
while ( v5 != v2 );
}
}

original_code:
void
SCH_iterate( SC_Hashtable * ht, OPFUNC op )
{
 int i, size = ht->tablesize;
 for ( i = 0; i < size; ++i )
 {
  int * node;
  int cnt = 0;
  for ( node = SA_atIndex(ht->array,ht->table[i]); node; node = SA_atIndex(ht->array,*node) )
  {
   cnt++;
   op( node + 1, i );
  }
  if ( cnt > ht->maxdepth )
   printf("bad cnt %d at %d\n",cnt,i);
 }
}

canonical_original_code:
void SCH_iterate(struct SC_Hashtable *ht, int (*op)(void *, int))
{
 int i; int size = ht->tablesize;
 for ( i = 0; i < size; ++i )
 {
  int *node;
  int cnt = 0;
  for ( node = SA_atIndex(ht->array,ht->table[i]); node; node = SA_atIndex(ht->array,*node) )
  {
   cnt++;
   op( node + 1, i );
  }
  if ( cnt > ht->maxdepth )
   printf("bad cnt %d at %d\n",cnt,i);
 }
}

variable_types: struct SC_Hashtable { int tablesize; int objsize; int count; int *table; struct SegArray { unsigned int mask; unsigned int shift; int numSegments; int objectSize; unsigned int numObjects; void *segments[16]; } *array; int maxdepth; unsigned long (*hash)(void *); int (*comp)(void *, void *); void (*del)(void *); int (*alloc)(); void (*dealloc)(int); } *

variable_types:
op
int (*)(void *, int)

variable_types: size int

variable_types: cnt int


decompiled_code:
__int64 __fastcall SCH_first(__int64 a1, _DWORD *a2)
{
unsigned int *v2; // r8
_DWORD *v4; // rdi
__int64 v5; // rax
__int64 v6; // r8
int v7; // er9
int v8; // er10
__int64 result; // rax

v2 = *(unsigned int **)(a1 + 16);
if ( *(int *)a1 <= 0 )
{
v8 = 0;
LABEL_7:
*a2 = v8;
result = 0LL;
}
else
{
v4 = *(_DWORD **)(a1 + 24);
while ( 1 )
{
v5 = SA_atIndex(v4, *v2);
if ( v5 )
break;
v2 = (unsigned int *)(v6 + 4);
if ( v8 == v7 + 1 )
goto LABEL_7;
}
*a2 = v7;
result = v5 + 4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, _DWORD *a2)
{
unsigned int *v2; // r8
_DWORD *v4; // rdi
__int64 v5; // rax
__int64 v6; // r8
int v7; // er9
int v8; // er10
__int64 result; // rax

v2 = *(unsigned int **)(a1 + 16);
if ( *(int *)a1 <= 0 )
{
v8 = 0;
LABEL_7:
*a2 = v8;
result = 0LL;
}
else
{
v4 = *(_DWORD **)(a1 + 24);
while ( 1 )
{
v5 = func0(v4, *v2);
if ( v5 )
break;
v2 = (unsigned int *)(v6 + 4);
if ( v8 == v7 + 1 )
goto LABEL_7;
}
*a2 = v7;
result = v5 + 4;
}
return result;
}

original_code:
void *
SCH_first( SC_Hashtable * ht, int * last )
{
 int * ret = 0;
 int * table = ht->table;
 int i, size = ht->tablesize;
 for ( i = 0; i < size; ++i )
  if ( (ret = SA_atIndex(ht->array,table[i])) )
   break;
 *last = i;
 return ret ? ret + 1 : 0;
}

canonical_original_code:
void *SCH_first(struct SC_Hashtable *ht, int *last)
{
 int *ret = 0;
 int *table = ht->table;
 int i; int size = ht->tablesize;
 for ( i = 0; i < size; ++i )
  if ( (ret = SA_atIndex(ht->array,table[i])) )
   break;
 *last = i;
 return ret ? ret + 1 : 0;
}

variable_types:
last
int *

variable_types:
ret
int *

variable_types:
table
int *


decompiled_code:
__int64 __fastcall SCH_next(__int64 a1, __int64 a2)
{
_DWORD *v2; // rdi
__int64 result; // rax
__int64 v4; // r9
_DWORD *v5; // r11
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // r8
int v9; // er10
_DWORD *v10; // r11

v2 = *(_DWORD **)(a1 + 24);
result = SA_atIndex(v2, *(_DWORD *)(a2 - 4));
if ( result )
{
LABEL_2:
result += 4LL;
return result;
}
LODWORD(v6) = *v5 + 1;
if ( *(_DWORD *)v4 > (int)v6 )
{
v7 = *(_QWORD *)(v4 + 16);
v6 = (int)v6;
while ( 1 )
{
result = SA_atIndex(v2, *(_DWORD *)(v7 + 4 * v6));
if ( result )
break;
v6 = v8 + 1;
if ( v9 <= (int)v6 )
return result;
}
*v10 = v8;
goto LABEL_2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
_DWORD *v2; // rdi
__int64 result; // rax
__int64 v4; // r9
_DWORD *v5; // r11
__int64 v6; // r8
__int64 v7; // r9
__int64 v8; // r8
int v9; // er10
_DWORD *v10; // r11

v2 = *(_DWORD **)(a1 + 24);
result = func0(v2, *(_DWORD *)(a2 - 4));
if ( result )
{
LABEL_2:
result += 4LL;
return result;
}
LODWORD(v6) = *v5 + 1;
if ( *(_DWORD *)v4 > (int)v6 )
{
v7 = *(_QWORD *)(v4 + 16);
v6 = (int)v6;
while ( 1 )
{
result = func0(v2, *(_DWORD *)(v7 + 4 * v6));
if ( result )
break;
v6 = v8 + 1;
if ( v9 <= (int)v6 )
return result;
}
*v10 = v8;
goto LABEL_2;
}
return result;
}

original_code:
void *
SCH_next( SC_Hashtable * ht, void * cur, int * last )
{
 int * ret = 0;
 int * table = ht->table;
 int * node = (int *)cur - 1;
 int * next = SA_atIndex(ht->array,*node);
 if ( next )
  return next + 1;
 int i, size = ht->tablesize;
 for ( i = *last + 1; i < size; ++i )
  if ( (ret = SA_atIndex(ht->array,table[i])) )
   break;
 if ( ret )
  *last = i;
 return ret ? ret + 1 : 0;
}

canonical_original_code:
void *SCH_next(struct SC_Hashtable *ht, void *cur, int *last)
{
 int *ret = 0;
 int *table = ht->table;
 int *node = (int *)cur - 1;
 int *next = SA_atIndex(ht->array,*node);
 if ( next )
  return next + 1;
 int i; int size = ht->tablesize;
 for ( i = *last + 1; i < size; ++i )
  if ( (ret = SA_atIndex(ht->array,table[i])) )
   break;
 if ( ret )
  *last = i;
 return ret ? ret + 1 : 0;
}

variable_types:
cur
void *

variable_types:
next
int *


original_code:
int cauchy_n_ones(int n, int w)
{
  int no;
  int cno;
  int nones;
  int i, j;
  int highbit;
  highbit = (1 << (w-1));
  if (PPs[w] == -1) {
    nones = 0;
    PPs[w] = galois_single_multiply(highbit, 2, w);
    for (i = 0; i < w; i++) {
      if (PPs[w] & (1 << i)) {
        ONEs[w][nones] = (1 << i);
        nones++;
      }
    }
    NOs[w] = nones;
  }
  no = 0;
  for (i = 0; i < w; i++) if (n & (1 << i)) no++;
  cno = no;
  for (i = 1; i < w; i++) {
    if (n & highbit) {
      n ^= highbit;
      n <<= 1;
      n ^= PPs[w];
      cno--;
      for (j = 0; j < NOs[w]; j++) {
        cno += (n & ONEs[w][j]) ? 1 : -1;
      }
    } else {
      n <<= 1;
    }
    no += cno;
  }
  return no;
}

canonical_original_code:
int cauchy_n_ones(int n, int w)
{
  int no;
  int cno;
  int nones;
  int i; int j;
  int highbit;
  highbit = (1 << (w-1));
  if (PPs[w] == -1) {
    nones = 0;
    PPs[w] = galois_single_multiply(highbit, 2, w);
    for (i = 0; i < w; i++) {
      if (PPs[w] & (1 << i)) {
        ONEs[w][nones] = (1 << i);
        nones++;
      }
    }
    NOs[w] = nones;
  }
  no = 0;
  for (i = 0; i < w; i++) if (n & (1 << i)) no++;
  cno = no;
  for (i = 1; i < w; i++) {
    if (n & highbit) {
      n ^= highbit;
      n <<= 1;
      n ^= PPs[w];
      cno--;
      for (j = 0; j < NOs[w]; j++) {
        cno += (n & ONEs[w][j]) ? 1 : -1;
      }
    } else {
      n <<= 1;
    }
    no += cno;
  }
  return no;
}

variable_types: n int

variable_types: w int

variable_types: no int

variable_types: cno int

variable_types: nones int

variable_types: i int

variable_types: j int

variable_types: highbit int


decompiled_code:
void __fastcall cauchy_improve_coding_matrix(int a1, int a2, unsigned int a3, unsigned int *a4)
{
unsigned int *v5; // rbx
int i; // ebp
__int64 v7; // rsi
unsigned int v8; // er12
_DWORD *v9; // r15
int v10; // er14
__int64 v11; // r15
int *v12; // rbx
int v13; // ebp
int v14; // edi
__int64 v15; // rbx
__int64 v16; // rax
__int64 v17; // rsi
int v18; // ebp
unsigned int *v19; // r14
unsigned int v20; // er12
__int64 v21; // rdi
int v22; // eax
unsigned int *v23; // rbp
unsigned int v24; // ebx
__int64 v25; // rdi
int *v26; // [rsp+0h] [rbp-78h]
__int64 v27; // [rsp+10h] [rbp-68h]
int v28; // [rsp+18h] [rbp-60h]
int v30; // [rsp+20h] [rbp-58h]
int v31; // [rsp+24h] [rbp-54h]
int v32; // [rsp+28h] [rbp-50h]
int v33; // [rsp+2Ch] [rbp-4Ch]
__int64 v34; // [rsp+30h] [rbp-48h]
unsigned int *v35; // [rsp+38h] [rbp-40h]

v30 = a1;
v35 = a4;
if ( a1 > 0 )
{
v5 = a4;
for ( i = 0; i != a1; ++i )
{
while ( 1 )
{
v7 = *v5;
if ( (_DWORD)v7 != 1 )
{
v8 = galois_single_divide(1LL, v7, a3);
if ( a2 > 0 )
break;
}
++i;
++v5;
if ( a1 == i )
goto LABEL_9;
}
v9 = v5;
v10 = 0;
do
{
++v10;
*v9 = galois_single_multiply((unsigned int)*v9, v8, a3);
v9 += a1;
}
while ( a2 != v10 );
++v5;
}
}
LABEL_9:
if ( a2 <= 1 )
return;
v31 = 1;
v34 = 4LL * a1;
v33 = a1;
v26 = (int *)&v35[(unsigned __int64)v34 / 4];
v27 = (unsigned int)(a1 - 1);
v11 = (__int64)&v35[v27 + 1 + a1];
do
{
if ( v30 <= 0 )
goto LABEL_23;
v12 = v26;
v13 = 0;
do
{
v14 = *v12++;
v13 += cauchy_n_ones(v14, a3);
}
while ( v12 != (int *)v11 );
v28 = v13;
v15 = 0LL;
v32 = -1;
while ( 1 )
{
v17 = (unsigned int)v26[v15];
if ( (_DWORD)v17 != 1 )
{
v18 = 0;
v19 = (unsigned int *)v26;
v20 = galois_single_divide(1LL, v17, a3);
do
{
v21 = *v19++;
v22 = galois_single_multiply(v21, v20, a3);
v18 += cauchy_n_ones(v22, a3);
}
while ( v19 != (unsigned int *)v11 );
if ( v18 < v28 )
break;
}
v16 = v15 + 1;
if ( v15 == v27 )
goto LABEL_22;
LABEL_16:
v15 = v16;
}
v28 = v18;
v32 = v15;
v16 = v15 + 1;
if ( v15 != v27 )
goto LABEL_16;
LABEL_22:
if ( v32 != -1 )
{
v23 = (unsigned int *)v26;
v24 = galois_single_divide(1LL, v35[v33 + v32], a3);
do
{
v25 = *v23++;
*(v23 - 1) = galois_single_multiply(v25, v24, a3);
}
while ( v23 != (unsigned int *)v11 );
}
LABEL_23:
++v31;
v26 = (int *)((char *)v26 + v34);
v33 += v30;
v11 += v34;
}
while ( a2 != v31 );
}

original_code:
void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix)
{
  int index, i, j, x;
  int tmp;
  int bno, tno, bno_index;
  for (j = 0; j < k; j++) {
    if (matrix[j] != 1) {
      tmp = galois_single_divide(1, matrix[j], w);
      index = j;
      for (i = 0; i < m; i++) {
        matrix[index] = galois_single_multiply(matrix[index], tmp, w);
        index += k;
      }
    }
  }
  for (i = 1; i < m; i++) {
    bno = 0;
    index = i*k;
    for (j = 0; j < k; j++) bno += cauchy_n_ones(matrix[index+j], w);
    bno_index = -1;
    for (j = 0; j < k; j++) {
      if (matrix[index+j] != 1) {
        tmp = galois_single_divide(1, matrix[index+j], w);
        tno = 0;
        for (x = 0; x < k; x++) {
          tno += cauchy_n_ones(galois_single_multiply(matrix[index+x], tmp, w), w);
        }
        if (tno < bno) {
          bno = tno;
          bno_index = j;
        }
      }
    }
    if (bno_index != -1) {
      tmp = galois_single_divide(1, matrix[index+bno_index], w);
      for (j = 0; j < k; j++) {
        matrix[index+j] = galois_single_multiply(matrix[index+j], tmp, w);
      }
    }
  }
}

canonical_original_code:
void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix)
{
  int index; int i; int j; int x;
  int tmp;
  int bno; int tno; int bno_index;
  for (j = 0; j < k; j++) {
    if (matrix[j] != 1) {
      tmp = galois_single_divide(1, matrix[j], w);
      index = j;
      for (i = 0; i < m; i++) {
        matrix[index] = galois_single_multiply(matrix[index], tmp, w);
        index += k;
      }
    }
  }
  for (i = 1; i < m; i++) {
    bno = 0;
    index = i*k;
    for (j = 0; j < k; j++) bno += cauchy_n_ones(matrix[index+j], w);
    bno_index = -1;
    for (j = 0; j < k; j++) {
      if (matrix[index+j] != 1) {
        tmp = galois_single_divide(1, matrix[index+j], w);
        tno = 0;
        for (x = 0; x < k; x++) {
          tno += cauchy_n_ones(galois_single_multiply(matrix[index+x], tmp, w), w);
        }
        if (tno < bno) {
          bno = tno;
          bno_index = j;
        }
      }
    }
    if (bno_index != -1) {
      tmp = galois_single_divide(1, matrix[index+bno_index], w);
      for (j = 0; j < k; j++) {
        matrix[index+j] = galois_single_multiply(matrix[index+j], tmp, w);
      }
    }
  }
}

variable_types: k int

variable_types: m int

variable_types:
matrix
int *

variable_types: index int

variable_types: x int

variable_types: tmp int

variable_types: bno int

variable_types: tno int


mkpath

original_code:
static void mkpath(const char *dir) {
        char tmp[256];
        char *p = ((void *)0);
        size_t len;
        snprintf(tmp, sizeof(tmp),"%s",dir);
        len = strlen(tmp);
        if(tmp[len - 1] == '/')
                tmp[len - 1] = 0;
        for(p = tmp + 1; *p; p++)
                if(*p == '/') {
                        *p = 0;
                        mkdir(tmp, (0400|0200|0100));
                        *p = '/';
                }
        mkdir(tmp, (0400|0200|0100));
}

canonical_original_code:
static void mkpath(char *dir) {
        char tmp[256];
        char *p = ((void *)0);
        unsigned long len;
        snprintf(tmp, sizeof(tmp),"%s",dir);
        len = strlen(tmp);
        if(tmp[len - 1] == '/')
                tmp[len - 1] = 0;
        for(p = tmp + 1; *p; p++)
                if(*p == '/') {
                        *p = 0;
                        mkdir(tmp, (0400|0200|0100));
                        *p = '/';
                }
        mkdir(tmp, (0400|0200|0100));
}

variable_types:
dir
char *

variable_types:
tmp
char [256]

variable_types:
p
char *

variable_types:
len
unsigned long


main

canonical_name: main

repo: kusha/iterations-counting

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

v4 = argv[1];
if ( !v4 )
goto LABEL_29;
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_29:
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) )
{
if ( !v7 )
goto LABEL_11;
v10 = argv[3];
if ( v10 )
{
v3 = strtod(v10, 0LL);
LABEL_11:
v11 = accuracy((unsigned int)v9);
while ( 1 )
{
v12 = __isoc99_scanf();
if ( v12 == -1 )
break;
if ( v12 )
{
if ( v7 )
{
v15 = *(double *)v17;
pwr("%lf", v17, *(double *)v17, v3, v11);
printf("%.10e\n", v15);
}
else if ( v6 )
{
v16 = *(double *)v17;
arctg("%.10e\n", v17, *(double *)v17, v11);
printf("%.10e\n", v16);
}
else if ( v5 )
{
v13 = *(double *)v17;
ash("%.10e\n", v17, *(double *)v17, v11);
printf("%.10e\n", v13);
}
}
else
{
__isoc99_scanf();
printf("%f\n", 0.0 / 0.0);
}
}
return 0;
}
fputs(ERRMSG3, stderr);
result = 1;
}
else
{
fputs(ERRMSG2, stderr);
result = 1;
}
return result;
}

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

v4 = argv[1];
if ( !v4 )
goto LABEL_29;
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_29:
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) )
{
if ( !v7 )
goto LABEL_11;
v10 = argv[3];
if ( v10 )
{
v3 = strtod(v10, 0LL);
LABEL_11:
v11 = func13((unsigned int)v9);
while ( 1 )
{
v12 = __isoc99_scanf();
if ( v12 == -1 )
break;
if ( v12 )
{
if ( v7 )
{
v15 = *(double *)v17;
pwr("%lf", v17, *(double *)v17, v3, v11);
printf("%.10e\n", v15);
}
else if ( v6 )
{
v16 = *(double *)v17;
func11("%.10e\n", v17, *(double *)v17, v11);
printf("%.10e\n", v16);
}
else if ( v5 )
{
v13 = *(double *)v17;
func12("%.10e\n", v17, *(double *)v17, v11);
printf("%.10e\n", v13);
}
}
else
{
__isoc99_scanf();
printf("%f\n", 0.0 / 0.0);
}
}
return 0;
}
fputs(ERRMSG3, stderr);
result = 1;
}
else
{
fputs(ERRMSG2, stderr);
result = 1;
}
return result;
}

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


decompiled_code:
__int64 print_help()
{
printf("%s", HELPMSG);
return 1LL;
}

canonical_decompiled_code:
__int64 func7()
{
printf("%s", HELPMSG);
return 1LL;
}

original_code:
int print_help() {
 printf("%s", HELPMSG);
 return 1;
}


decompiled_code:
__m128d __fastcall f_abs(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)xmmword_402310);
return result;
}

canonical_decompiled_code:
__m128d __fastcall func8(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)xmmword_402310);
return result;
}

original_code:
double f_abs (double x) {
 if (x<0) {
  return -x;
 } else {
  return x;
 }
}

canonical_original_code:
double f_abs(double x) {
 if (x<0) {
  return -x;
 } else {
  return x;
 }
}

return_type: double


sqr

original_code:
double sqr (double x, double eps) {
 if (x<0) {
  return 0.0/0.0;
 }
 else if (x==0) {
  return 0;
 }
 double c = 1;
 if (x<1) {
  c = x;
  x = 1/x;
 }
 double aprx=1;
 double previous=0;
 double q;
 do {
  q = x/aprx;
  previous = aprx;
  aprx=(q+aprx)/2;
 } while (f_abs(previous-aprx)>eps);
 return c*aprx;
}

canonical_original_code:
double sqr(double x, double eps) {
 if (x<0) {
  return 0.0/0.0;
 }
 else if (x==0) {
  return 0;
 }
 double c = 1;
 if (x<1) {
  c = x;
  x = 1/x;
 }
 double aprx = 1;
 double previous = 0;
 double q;
 do {
  q = x/aprx;
  previous = aprx;
  aprx=(q+aprx)/2;
 } while (f_abs(previous-aprx)>eps);
 return c*aprx;
}

variable_types: c double

variable_types: aprx double

variable_types: previous double

variable_types: q double


ln

original_code:
double ln (double x, double eps) {
 if (x<0) {
  return 0.0/0.0;
 }
 else if (x==0) {
  return -1.0/0.0;
 }
 else if (x==1) {
  return 0.0;
 }
 int div_c=0;
 int mul_c=0;
 if (x>=1) {
  while (x>=1) {
   x = x / CONST_E;
   ++div_c;
  }
 } else {
  while ((x * CONST_E)<1) {
   x = x * CONST_E;
   ++mul_c;
  }
 }
 --x;
 double sum = 0;
 double previous = 0;
 double next = x;
 double xpow = x;
 int i = 2;
 do {
  sum = sum + next;
  previous = next;
  xpow = xpow * x * -1;
  next = xpow/i;
  ++i;
 } while (f_abs(previous-next)>eps);
 if (div_c) {sum += div_c;}
 if (mul_c) {sum -= mul_c;}
 return sum;
}

canonical_original_code:
double ln(double x, double eps) {
 if (x<0) {
  return 0.0/0.0;
 }
 else if (x==0) {
  return -1.0/0.0;
 }
 else if (x==1) {
  return 0.0;
 }
 int div_c = 0;
 int mul_c = 0;
 if (x>=1) {
  while (x>=1) {
   x = x / CONST_E;
   ++div_c;
  }
 } else {
  while ((x * CONST_E)<1) {
   x = x * CONST_E;
   ++mul_c;
  }
 }
 --x;
 double sum = 0;
 double previous = 0;
 double next = x;
 double xpow = x;
 int i = 2;
 do {
  sum = sum + next;
  previous = next;
  xpow = xpow * x * -1;
  next = xpow/i;
  ++i;
 } while (f_abs(previous-next)>eps);
 if (div_c) {sum += div_c;}
 if (mul_c) {sum -= mul_c;}
 return sum;
}

variable_types: sum double

variable_types: next double

variable_types: xpow double

variable_types: i int


arctg

original_code:
double arctg (double x, double eps) {
 double c=1;
 if(x<0){
  x = -x;
  c= -1;
 }
 if (x==1) {return CONST_PI_4;}
 _Bool Pi_flag = 0;
 if (x>1) {x = 1/x; Pi_flag =1;}
 double sum = 0;
 double previous = 0;
 double next = x;
 double xpow = x;
 double x2 = x*x;
 int i = 3;
 do {
  sum = sum + next;
  previous = next;
  xpow = xpow * x2 * -1;
  next = xpow/i;
  i += 2;
 } while (f_abs(next-previous)>=eps);
 if (Pi_flag) {
  sum = (CONST_PI_2 - sum);
 }
 return c*sum;
}

canonical_original_code:
double arctg(double x, double eps) {
 double c = 1;
 if(x<0){
  x = -x;
  c= -1;
 }
 if (x==1) {return CONST_PI_4;}
 _Bool Pi_flag = 0;
 if (x>1) {x = 1/x; Pi_flag =1;}
 double sum = 0;
 double previous = 0;
 double next = x;
 double xpow = x;
 double x2 = x*x;
 int i = 3;
 do {
  sum = sum + next;
  previous = next;
  xpow = xpow * x2 * -1;
  next = xpow/i;
  i += 2;
 } while (f_abs(next-previous)>=eps);
 if (Pi_flag) {
  sum = (CONST_PI_2 - sum);
 }
 return c*sum;
}


ash

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

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

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

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

if ( a1 < 0 )
return 1.0;
result = 1.0;
v2 = a1 + 1;
v3 = 0;
do
{
result = result / 10.0;
++v3;
}
while ( v3 != v2 );
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


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


main

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

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall update_money(int a1)
{
__int64 v1; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rdx

v1 = (unsigned int)money;
if ( !idkfa_enabled )
{
v1 = (unsigned int)(a1 + money);
money += a1;
}
if ( (int)v1 < 0 )
{
money = 0;
v1 = 0LL;
}
sprintf(moneytext, "money %6d", v1);
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


decompiled_code:
__int64 __fastcall update_score(int a1)
{
__int64 v1; // rdx

v1 = (unsigned int)(score + a1);
if ( score + a1 < 0 )
{
score = 0;
v1 = 0LL;
}
else
{
score += a1;
}
sprintf(scoretext, "score %6d", v1);
return updaterect(3LL, 13LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdx

v1 = (unsigned int)(score + a1);
if ( score + a1 < 0 )
{
score = 0;
v1 = 0LL;
}
else
{
score += a1;
}
sprintf(scoretext, "score %6d", v1);
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)
{
__int64 v1; // rdx

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

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

v1 = (unsigned int)lives;
if ( !iddqd_enabled )
{
v1 = (unsigned int)(a1 + lives);
lives += a1;
}
if ( (int)v1 < 0 )
{
lives = 0;
}
else if ( (_DWORD)v1 )
{
sprintf(lifetext, "lives %6d", v1);
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; // er12
unsigned int v3; // er14
bool v4; // r10
__int64 i; // rbx
unsigned int v6; // eax
unsigned int v7; // eax
bool v8; // [rsp+Fh] [rbp-41h]
bool v9; // [rsp+Fh] [rbp-41h]
char v10[4]; // [rsp+10h] [rbp-40h] BYREF
char v11[4]; // [rsp+14h] [rbp-3Ch] BYREF
__int64 v12[7]; // [rsp+18h] [rbp-38h] BYREF

get_cursor_location(v10, v11);
result = (unsigned int)current_screen;
switch ( current_screen )
{
case 1:
result = dword_1424 | dword_13E8 | dword_13AC | dword_1370 | dword_1420 | dword_13E4 | dword_13A8 | dword_136C | dword_141C | dword_13E0 | dword_13A4 | (unsigned int)dword_1368;
if ( dword_1424 | dword_13E8 | dword_13AC | dword_1370 | dword_1420 | dword_13E4 | dword_13A8 | dword_136C | dword_141C | dword_13E0 | dword_13A4 | dword_1368 )
result = draw_menu();
return result;
case 2:
v1 = 0LL;
v2 = 0;
v3 = 0;
draw_cursor(screen);
break;
case 3:
return draw_highscores();
case 4:
return draw_credits();
case 5:
return draw_tutorial();
default:
return result;
}
do
{
v4 = (int)v3 > 7;
for ( i = 0LL; i != 15; ++i )
{
while ( v4 && v2 == 0 && (int)i > 12 )
{
v2 = field[i + v1];
if ( v2 == 1 )
{
v9 = v4;
draw_hint_text(screen);
draw_buttons(screen);
draw_text_color(screen, costtext, 265LL, 416LL, 255LL, 255LL, 0LL);
v4 = v9;
break;
}
++i;
v2 = 0;
if ( i == 15 )
goto LABEL_16;
}
if ( field[i + v1] == 1 )
{
v8 = v4;
draw_tower(v3, (unsigned int)i);
draw_enemy(v3, (unsigned int)i);
draw_projectile(v3, (unsigned int)i);
v4 = v8;
}
}
LABEL_16:
++v3;
v1 += 15LL;
}
while ( v3 != 20 );
if ( dword_1134 == 1 )
{
v12[0] = 0x20002000000060LL;
v6 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, v12, v6);
}
if ( dword_14FC == 1 )
{
v12[0] = 0x20002000400260LL;
v7 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, v12, v7);
}
if ( dword_147C == 1 || dword_14B8 == 1 || dword_14F4 == 1 )
draw_text(screen, fpstext, 520LL, 0LL);
if ( dword_12D4 | dword_1298 | dword_125C | dword_1220 | dword_11E4 | dword_11A8 | dword_116C | dword_1130 | dword_12D0 | dword_1294 | dword_1258 | dword_121C | dword_11E0 | dword_11A4 | dword_1168 | dword_112C )
draw_numbers();
if ( dword_14F4 | dword_14B8 | dword_147C | dword_1440 )
draw_text(screen, fpstext, 520LL, 0LL);
result = dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1314 | dword_12D8 | dword_129C | (unsigned int)dword_1260;
if ( dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1314 | dword_12D8 | dword_129C | dword_1260 )
result = draw_buttons2(screen);
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
__int64 v1; // r15
int v2; // er12
unsigned int v3; // er14
bool v4; // r10
__int64 i; // rbx
unsigned int v6; // eax
unsigned int v7; // eax
bool v8; // [rsp+Fh] [rbp-41h]
bool v9; // [rsp+Fh] [rbp-41h]
char v10[4]; // [rsp+10h] [rbp-40h] BYREF
char v11[4]; // [rsp+14h] [rbp-3Ch] BYREF
__int64 v12[7]; // [rsp+18h] [rbp-38h] BYREF

get_cursor_location(v10, v11);
result = (unsigned int)current_screen;
switch ( current_screen )
{
case 1:
result = dword_1424 | dword_13E8 | dword_13AC | dword_1370 | dword_1420 | dword_13E4 | dword_13A8 | dword_136C | dword_141C | dword_13E0 | dword_13A4 | (unsigned int)dword_1368;
if ( dword_1424 | dword_13E8 | dword_13AC | dword_1370 | dword_1420 | dword_13E4 | dword_13A8 | dword_136C | dword_141C | dword_13E0 | dword_13A4 | dword_1368 )
result = draw_menu();
return result;
case 2:
v1 = 0LL;
v2 = 0;
v3 = 0;
draw_cursor(screen);
break;
case 3:
return draw_highscores();
case 4:
return draw_credits();
case 5:
return draw_tutorial();
default:
return result;
}
do
{
v4 = (int)v3 > 7;
for ( i = 0LL; i != 15; ++i )
{
while ( v4 && v2 == 0 && (int)i > 12 )
{
v2 = field[i + v1];
if ( v2 == 1 )
{
v9 = v4;
draw_hint_text(screen);
draw_buttons(screen);
draw_text_color(screen, costtext, 265LL, 416LL, 255LL, 255LL, 0LL);
v4 = v9;
break;
}
++i;
v2 = 0;
if ( i == 15 )
goto LABEL_16;
}
if ( field[i + v1] == 1 )
{
v8 = v4;
draw_tower(v3, (unsigned int)i);
draw_enemy(v3, (unsigned int)i);
draw_projectile(v3, (unsigned int)i);
v4 = v8;
}
}
LABEL_16:
++v3;
v1 += 15LL;
}
while ( v3 != 20 );
if ( dword_1134 == 1 )
{
v12[0] = 0x20002000000060LL;
v6 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, v12, v6);
}
if ( dword_14FC == 1 )
{
v12[0] = 0x20002000400260LL;
v7 = SDL_MapRGB(*(_QWORD *)(screen + 8), 0LL, 0LL, 0LL);
SDL_FillRect(screen, v12, v7);
}
if ( dword_147C == 1 || dword_14B8 == 1 || dword_14F4 == 1 )
draw_text(screen, fpstext, 520LL, 0LL);
if ( dword_12D4 | dword_1298 | dword_125C | dword_1220 | dword_11E4 | dword_11A8 | dword_116C | dword_1130 | dword_12D0 | dword_1294 | dword_1258 | dword_121C | dword_11E0 | dword_11A4 | dword_1168 | dword_112C )
draw_numbers();
if ( dword_14F4 | dword_14B8 | dword_147C | dword_1440 )
draw_text(screen, fpstext, 520LL, 0LL);
result = dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1314 | dword_12D8 | dword_129C | (unsigned int)dword_1260;
if ( dword_1404 | dword_13C8 | dword_138C | dword_1350 | dword_1314 | dword_12D8 | dword_129C | dword_1260 )
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_6E4);
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_6E4);
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; // er12
__int64 result; // rax

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

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
__int64 result; // rax

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

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
__int64 v3; // rdx
int v4; // ecx
__int64 v5; // rax

if ( a1 <= 19 && a2 <= 14 )
{
v2 = 15LL * a1 + a2;
if ( !field[v2] )
{
v3 = updatefield;
v4 = current_screen;
field[v2] = 1;
word_6E4[4 * v3] = 32 * a1;
v5 = v3;
word_6E6[4 * v3] = 32 * a2;
dword_6E8[2 * v3] = 2097184;
if ( v4 == 2 )
{
SDL_UpperBlit(background, &word_6E4[4 * v3], screen, &word_6E4[4 * v3]);
v5 = updatefield;
v4 = current_screen;
}
if ( (unsigned int)(v4 - 3) <= 2 || v4 == 1 )
{
SDL_UpperBlit(menubackground, &word_6E4[4 * v5], screen, &word_6E4[4 * v5]);
LODWORD(v5) = updatefield;
}
updatefield = v5 + 1;
}
}
}

canonical_decompiled_code:
void __fastcall func3(int a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rdx
int v4; // ecx
__int64 v5; // rax

if ( a1 <= 19 && a2 <= 14 )
{
v2 = 15LL * a1 + a2;
if ( !field[v2] )
{
v3 = updatefield;
v4 = current_screen;
field[v2] = 1;
word_6E4[4 * v3] = 32 * a1;
v5 = v3;
word_6E6[4 * v3] = 32 * a2;
dword_6E8[2 * v3] = 2097184;
if ( v4 == 2 )
{
SDL_UpperBlit(background, &word_6E4[4 * v3], screen, &word_6E4[4 * v3]);
v5 = updatefield;
v4 = current_screen;
}
if ( (unsigned int)(v4 - 3) <= 2 || v4 == 1 )
{
SDL_UpperBlit(menubackground, &word_6E4[4 * v5], screen, &word_6E4[4 * v5]);
LODWORD(v5) = updatefield;
}
updatefield = v5 + 1;
}
}
}

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 v0; // eax
int i; // er12
int j; // ebx
int v3; // esi

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

canonical_decompiled_code:
void func4()
{
int v0; // eax
int i; // er12
int j; // ebx
int v3; // esi

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

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_1579);
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_1579);
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)
{
current_screen = 3;
messageno = a1;
return update_all();
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
current_screen = 3;
messageno = a1;
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);
draw_text(screen, (char *)&messages + 50 * messageno, 200LL, 250LL);
result = (unsigned int)messageno;
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);
draw_text(screen, (char *)&messages + 50 * messageno, 200LL, 250LL);
result = (unsigned int)messageno;
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()
{
__int64 v0; // rbx
const char *i; // rsi
__int64 v2; // rcx
__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]
__int64 v13; // [rsp+0h] [rbp-20h]

if ( !sprites_loaded )
load_sprites();
if ( redraw )
{
v0 = 0LL;
for ( i = "basic gameplay"; ; i = tutorials[v0] )
{
v2 = (unsigned int)(16 * v0 + 160);
if ( hoverchoice == (_DWORD)v0++ )
draw_text_color(screen, i, 16LL, v2, 255LL, 255LL, 0LL);
else
draw_text(screen, i, 16LL, v2);
if ( v0 == 4 )
break;
}
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_9C2 = 232;
word_9BA = 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the least", 232LL, 240LL);
word_9C2 += 32;
word_9BA += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the farthest", 232LL, 272LL);
word_9C2 += 32;
word_9BA += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with most hp", 232LL, 304LL);
word_9C2 += 32;
word_9BA += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with least hp", 232LL, 336LL);
word_9C2 += 32;
word_9BA += 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(v3) = 255;
draw_text_color(screen, "2", 232LL, 176LL, 0LL, 255LL, v3);
draw_text(screen, "build artificial volcano", 280LL, 176LL);
LODWORD(v4) = 255;
draw_text_color(screen, "3", 232LL, 192LL, 0LL, 255LL, v4);
draw_text(screen, "build freezer", 280LL, 192LL);
LODWORD(v5) = 255;
draw_text_color(screen, "s", 232LL, 208LL, 0LL, 255LL, v5);
draw_text(screen, "sell tower", 280LL, 208LL);
LODWORD(v6) = 255;
draw_text_color(screen, aQwertp, 232LL, 224LL, 0LL, 255LL, v6);
draw_text(screen, "shoot enemy travelled the least", 280LL, 224LL);
LODWORD(v7) = 255;
draw_text_color(screen, &aQwertp[1], 232LL, 240LL, 0LL, 255LL, v7);
draw_text(screen, "shoot enemy travelled the farthest", 280LL, 240LL);
LODWORD(v8) = 255;
draw_text_color(screen, &aQwertp[2], 232LL, 256LL, 0LL, 255LL, v8);
draw_text(screen, "shoot enemy with most hp", 280LL, 256LL);
LODWORD(v9) = 255;
draw_text_color(screen, &aQwertp[3], 232LL, 272LL, 0LL, 255LL, v9);
draw_text(screen, "shoot enemy with least hp", 280LL, 272LL);
LODWORD(v10) = 255;
draw_text_color(screen, &aQwertp[4], 232LL, 288LL, 0LL, 255LL, v10);
draw_text(screen, "shoot the fastest enemy", 280LL, 288LL);
LODWORD(v11) = 255;
draw_text_color(screen, &aQwertp[5], 232LL, 304LL, 0LL, 255LL, v11);
draw_text(screen, "pause tower", 280LL, 304LL);
LODWORD(v12) = 255;
draw_text_color(screen, "space", 232LL, 320LL, 0LL, 255LL, v12);
draw_text(screen, "pause the game", 280LL, 320LL);
LODWORD(v13) = 255;
draw_text_color(screen, "esc", 232LL, 336LL, 0LL, 255LL, v13);
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()
{
__int64 v0; // rbx
const char *i; // rsi
__int64 v2; // rcx
__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]
__int64 v13; // [rsp+0h] [rbp-20h]

if ( !sprites_loaded )
func0();
if ( redraw )
{
v0 = 0LL;
for ( i = "basic gameplay"; ; i = tutorials[v0] )
{
v2 = (unsigned int)(16 * v0 + 160);
if ( hoverchoice == (_DWORD)v0++ )
draw_text_color(screen, i, 16LL, v2, 255LL, 255LL, 0LL);
else
draw_text(screen, i, 16LL, v2);
if ( v0 == 4 )
break;
}
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_9C2 = 232;
word_9BA = 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the least", 232LL, 240LL);
word_9C2 += 32;
word_9BA += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy travelled the farthest", 232LL, 272LL);
word_9C2 += 32;
word_9BA += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with most hp", 232LL, 304LL);
word_9C2 += 32;
word_9BA += 24;
SDL_UpperBlit(buttonsurface2, &tower_src, screen, &tower_dst);
draw_text(screen, "shoot enemy with least hp", 232LL, 336LL);
word_9C2 += 32;
word_9BA += 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(v3) = 255;
draw_text_color(screen, "2", 232LL, 176LL, 0LL, 255LL, v3);
draw_text(screen, "build artificial volcano", 280LL, 176LL);
LODWORD(v4) = 255;
draw_text_color(screen, "3", 232LL, 192LL, 0LL, 255LL, v4);
draw_text(screen, "build freezer", 280LL, 192LL);
LODWORD(v5) = 255;
draw_text_color(screen, "s", 232LL, 208LL, 0LL, 255LL, v5);
draw_text(screen, "sell tower", 280LL, 208LL);
LODWORD(v6) = 255;
draw_text_color(screen, aQwertp, 232LL, 224LL, 0LL, 255LL, v6);
draw_text(screen, "shoot enemy travelled the least", 280LL, 224LL);
LODWORD(v7) = 255;
draw_text_color(screen, &aQwertp[1], 232LL, 240LL, 0LL, 255LL, v7);
draw_text(screen, "shoot enemy travelled the farthest", 280LL, 240LL);
LODWORD(v8) = 255;
draw_text_color(screen, &aQwertp[2], 232LL, 256LL, 0LL, 255LL, v8);
draw_text(screen, "shoot enemy with most hp", 280LL, 256LL);
LODWORD(v9) = 255;
draw_text_color(screen, &aQwertp[3], 232LL, 272LL, 0LL, 255LL, v9);
draw_text(screen, "shoot enemy with least hp", 280LL, 272LL);
LODWORD(v10) = 255;
draw_text_color(screen, &aQwertp[4], 232LL, 288LL, 0LL, 255LL, v10);
draw_text(screen, "shoot the fastest enemy", 280LL, 288LL);
LODWORD(v11) = 255;
draw_text_color(screen, &aQwertp[5], 232LL, 304LL, 0LL, 255LL, v11);
draw_text(screen, "pause tower", 280LL, 304LL);
LODWORD(v12) = 255;
draw_text_color(screen, "space", 232LL, 320LL, 0LL, 255LL, v12);
draw_text(screen, "pause the game", 280LL, 320LL);
LODWORD(v13) = 255;
draw_text_color(screen, "esc", 232LL, 336LL, 0LL, 255LL, v13);
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;
}


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

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

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

if ( (unsigned int)(a1 - 16) <= 0xA0 )
{
v2 = a2 - 160;
if ( (unsigned int)v2 <= 0x3F )
hoverchoice = v2 >> 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 v4; // edi
int v5; // esi
__int64 v6; // rdi
__int64 v7; // rsi

updaterect((unsigned int)cell_x, (unsigned int)cell_y);
v4 = a1 + 31;
v5 = a2 + 31;
if ( a1 >= 0 )
v4 = a1;
v6 = (unsigned int)(v4 >> 5);
if ( a2 >= 0 )
v5 = a2;
cell_x = v6;
v7 = (unsigned int)(v5 >> 5);
cell_y = v7;
return updaterect(v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v4; // edi
int v5; // esi
__int64 v6; // rdi
__int64 v7; // rsi

updaterect((unsigned int)cell_x, (unsigned int)cell_y);
v4 = a1 + 31;
v5 = a2 + 31;
if ( a1 >= 0 )
v4 = a1;
v6 = (unsigned int)(v4 >> 5);
if ( a2 >= 0 )
v5 = a2;
cell_x = v6;
v7 = (unsigned int)(v5 >> 5);
cell_y = v7;
return updaterect(v6, v7);
}

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 ( a1 > 19 || a2 > 14 )
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 ( a1 > 19 || a2 > 14 )
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

result = 0LL;
while ( 1 )
{
v3 = button_rects2[4 * result];
if ( v3 < a1 && (unsigned __int16)word_624[4 * result] + v3 > a1 )
{
v4 = word_622[4 * result];
if ( v4 < a2 && (unsigned __int16)word_626[4 * result] + v4 > a2 )
break;
}
if ( ++result == 7 )
{
button2tooltip = -1;
return result;
}
}
button2tooltip = result;
return result;
}

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

result = 0LL;
while ( 1 )
{
v3 = button_rects2[4 * result];
if ( v3 < a1 && (unsigned __int16)word_624[4 * result] + v3 > a1 )
{
v4 = word_622[4 * result];
if ( v4 < a2 && (unsigned __int16)word_626[4 * result] + v4 > a2 )
break;
}
if ( ++result == 7 )
{
button2tooltip = -1;
return result;
}
}
button2tooltip = result;
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 )
{
dword_604 = 0;
LABEL_4:
dword_608 = 0;
return draw_buttons(screen);
}
button_pressed[0] = 0;
if ( a1 == 2 )
goto LABEL_4;
dword_604 = 0;
if ( a1 != 3 )
goto LABEL_4;
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 )
{
dword_604 = 0;
LABEL_4:
dword_608 = 0;
return func2(screen);
}
button_pressed[0] = 0;
if ( a1 == 2 )
goto LABEL_4;
dword_604 = 0;
if ( a1 != 3 )
goto LABEL_4;
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 v2; // rax
int v4; // ecx
int v5; // ebx
__int64 v6; // rsi
int v7; // edx
__int64 result; // rax
int v9; // edx

v2 = 0LL;
do
{
v4 = button_rects[4 * v2];
v5 = v2;
if ( v4 + (unsigned __int16)word_664[4 * v2] >= a1 && v4 <= a1 )
{
v9 = word_662[4 * v2];
if ( v9 <= a2 && (unsigned __int16)word_666[4 * v2] + v9 >= a2 )
{
button_pressed[(int)v2] = 1;
towerbutton = 3 * v2;
sprintf(&costtext, "%6d", tower_definitions[51 * (_DWORD)v2 + 8]);
if ( v5 )
{
button_pressed[0] = 0;
if ( v5 != 1 )
{
dword_604 = 0;
return draw_buttons(screen);
}
}
else
{
dword_604 = 0;
}
dword_608 = 0;
return draw_buttons(screen);
}
}
++v2;
}
while ( v2 != 3 );
v6 = 0LL;
while ( 1 )
{
v7 = button_rects2[4 * v6];
result = v7 + (unsigned int)(unsigned __int16)word_624[4 * v6];
if ( (int)result >= a1 && v7 <= a1 )
{
result = (unsigned int)word_622[4 * v6];
if ( (int)result <= a2 )
{
result = (unsigned __int16)word_626[4 * v6] + (unsigned int)result;
if ( (int)result >= a2 )
break;
}
}
if ( ++v6 == 7 )
return result;
}
if ( !(_DWORD)v6 )
return sell_tower(selected_tower);
if ( (_DWORD)v6 == 6 )
return toggle_shooting(selected_tower);
return tower_algorithm(selected_tower);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2)
{
__int64 v2; // rax
int v4; // ecx
int v5; // ebx
__int64 v6; // rsi
int v7; // edx
__int64 result; // rax
int v9; // edx

v2 = 0LL;
do
{
v4 = button_rects[4 * v2];
v5 = v2;
if ( v4 + (unsigned __int16)word_664[4 * v2] >= a1 && v4 <= a1 )
{
v9 = word_662[4 * v2];
if ( v9 <= a2 && (unsigned __int16)word_666[4 * v2] + v9 >= a2 )
{
button_pressed[(int)v2] = 1;
towerbutton = 3 * v2;
sprintf(&costtext, "%6d", tower_definitions[51 * (_DWORD)v2 + 8]);
if ( v5 )
{
button_pressed[0] = 0;
if ( v5 != 1 )
{
dword_604 = 0;
return func2(screen);
}
}
else
{
dword_604 = 0;
}
dword_608 = 0;
return func2(screen);
}
}
++v2;
}
while ( v2 != 3 );
v6 = 0LL;
while ( 1 )
{
v7 = button_rects2[4 * v6];
result = v7 + (unsigned int)(unsigned __int16)word_624[4 * v6];
if ( (int)result >= a1 && v7 <= a1 )
{
result = (unsigned int)word_622[4 * v6];
if ( (int)result <= a2 )
{
result = (unsigned __int16)word_626[4 * v6] + (unsigned int)result;
if ( (int)result >= a2 )
break;
}
}
if ( ++v6 == 7 )
return result;
}
if ( !(_DWORD)v6 )
return sell_tower(selected_tower);
if ( (_DWORD)v6 == 6 )
return toggle_shooting(selected_tower);
return tower_algorithm(selected_tower);
}

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()
{
unsigned __int64 v0; // rbx
const char *i; // rsi
__int64 v2; // rcx
__int64 result; // rax

v0 = 0LL;
for ( i = "code"; ; i = (&credits)[v0 / 8] )
{
v2 = (unsigned int)(2 * v0 + 200);
v0 += 8LL;
result = draw_text(screen, i, 200LL, v2);
if ( v0 == 96 )
break;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned __int64 v0; // rbx
const char *i; // rsi
__int64 v2; // rcx
__int64 result; // rax

v0 = 0LL;
for ( i = "code"; ; i = (&credits)[v0 / 8] )
{
v2 = (unsigned int)(2 * v0 + 200);
v0 += 8LL;
result = draw_text(screen, i, 200LL, v2);
if ( v0 == 96 )
break;
}
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)));
    }
}