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

for ( result = a2; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

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

for ( result = a2; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
uint ah_bucket_length_acc(ah_bucket* bucket, uint acc)
{
  if(((void *)0) == bucket) {
    return acc;
  } else {
    return ah_bucket_length_acc(bucket->next, acc + 1);
  }
}

canonical_original_code:
unsigned int ah_bucket_length_acc(struct ah_t_bucket *bucket, unsigned int acc)
{
  if(((void *)0) == bucket) {
    return acc;
  } else {
    return ah_bucket_length_acc(bucket->next, acc + 1);
  }
}

variable_types:
acc
unsigned int


repo: rnakano/amitahash

decompiled_code:
__int64 __fastcall ah_bucket_length(__int64 a1)
{
return ah_bucket_length_acc(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
return func16(a1, 0);
}

original_code:
uint ah_bucket_length(ah_bucket* bucket)
{
  return ah_bucket_length_acc(bucket, 0);
}

canonical_original_code:
unsigned int ah_bucket_length(struct ah_t_bucket *bucket)
{
  return ah_bucket_length_acc(bucket, 0);
}

variable_types: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; } *

return_type: unsigned int


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

if ( a1 )
{
v1 = a1;
do
{
printf(" %s ", *(const char **)v1);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return putchar(10);
}

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

if ( a1 )
{
v1 = a1;
do
{
printf(" %s ", *(const char **)v1);
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void ah_bucket_print(ah_bucket* bucket)
{
  if(((void *)0) == bucket) {
    printf("\n");
    return;
  }
  printf(" %s ", bucket->key);
  ah_bucket_print(bucket->next);
}

canonical_original_code:
void ah_bucket_print(struct ah_t_bucket *bucket)
{
  if(((void *)0) == bucket) {
    printf("\n");
    return;
  }
  printf(" %s ", bucket->key);
  ah_bucket_print(bucket->next);
}

return_type: void

user_defined_types: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; }


decompiled_code:
__int64 __fastcall ah_bucket_free(__int64 a1)
{
ah_free(*(_QWORD *)(a1 + 8));
return ah_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1)
{
func25(*(_QWORD *)(a1 + 8));
return func25(a1);
}

original_code:
void ah_bucket_free(ah_bucket* bucket)
{
  ah_free(bucket->value);
  ah_free(bucket);
}

canonical_original_code:
void ah_bucket_free(struct ah_t_bucket *bucket)
{
  ah_free(bucket->value);
  ah_free(bucket);
}


decompiled_code:
void __fastcall ah_bucket_remove_acc(__int64 a1, _QWORD *a2, const char *a3)
{
int v5; // eax
__int64 v6; // rdi
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v7[0] = a1;
if ( a1 )
{
v5 = strcmp(*(const char **)a1, a3);
v6 = *(_QWORD *)(a1 + 16);
if ( v5 )
{
ah_bucket_remove_acc(v6, v7, a3);
}
else
{
*a2 = v6;
ah_bucket_free(a1);
}
}
}

original_code:
void ah_bucket_remove_acc(ah_bucket* bucket, ah_bucket** prev, char* key)
{
  if(((void *)0) == bucket) {
    return;
  }
  if(strcmp(bucket->key, key) == 0) {
    *prev = bucket->next;
    ah_bucket_free(bucket);
    return;
  }
  ah_bucket_remove_acc(bucket->next, &bucket, key);
}

canonical_original_code:
void ah_bucket_remove_acc(struct ah_t_bucket *bucket, struct ah_t_bucket **prev, char *key)
{
  if(((void *)0) == bucket) {
    return;
  }
  if(strcmp(bucket->key, key) == 0) {
    *prev = bucket->next;
    ah_bucket_free(bucket);
    return;
  }
  ah_bucket_remove_acc(bucket->next, &bucket, key);
}

variable_types:
prev
struct ah_t_bucket **

variable_types:
key
char *


decompiled_code:
void __fastcall ah_bucket_remove_i(__int64 *a1, const char *a2)
{
__int64 v2; // r12
__int64 v3; // rbx

v2 = *a1;
if ( *a1 && (v3 = *(_QWORD *)(v2 + 16)) != 0 && !strcmp(*(const char **)v2, a2) )
{
*a1 = v3;
ah_bucket_free(v2);
}
else
{
ah_bucket_remove_acc(v2, a1, a2);
}
}

original_code:
void ah_bucket_remove_i(ah_bucket** bucket, char* key)
{
  if(*bucket != ((void *)0) && (*bucket)->next != ((void *)0) && strcmp((*bucket)->key, key) == 0) {
    ah_bucket* tmp = *bucket;
    *bucket = tmp->next;
    ah_bucket_free(tmp);
  } else {
    ah_bucket_remove_acc(*bucket, bucket, key);
  }
}

canonical_original_code:
void ah_bucket_remove_i(struct ah_t_bucket **bucket, char *key)
{
  if(*bucket != ((void *)0) && (*bucket)->next != ((void *)0) && strcmp((*bucket)->key, key) == 0) {
    struct ah_t_bucket *tmp = *bucket;
    *bucket = tmp->next;
    ah_bucket_free(tmp);
  } else {
    ah_bucket_remove_acc(*bucket, bucket, key);
  }
}

variable_types: struct ah_t_bucket { char *key; char *value; struct ah_t_bucket *next; } **


decompiled_code:
void __fastcall ah_bucket_remove(__int64 *a1, const char *a2)
{
__int64 v2; // r12
int v3; // eax
__int64 v4; // rbp
int v5; // er8
__int64 v6; // rax

v2 = *a1;
if ( *a1 )
{
v3 = strcmp(*(const char **)v2, a2);
v4 = *(_QWORD *)(v2 + 16);
if ( v3 )
{
if ( v4 )
{
while ( 1 )
{
v5 = strcmp(*(const char **)v4, a2);
v6 = *(_QWORD *)(v4 + 16);
if ( !v5 )
break;
v2 = v4;
if ( !v6 )
return;
v4 = *(_QWORD *)(v4 + 16);
}
*(_QWORD *)(v2 + 16) = v6;
ah_bucket_free(v4);
}
}
else
{
*a1 = v4;
ah_bucket_free(v2);
}
}
}

original_code:
void ah_bucket_remove(ah_bucket** bucket, char* key)
{
  ah_bucket* tgt = *bucket;
  ah_bucket* prev;
  if(((void *)0) == *bucket) return;
  if(strcmp(tgt->key, key) == 0) {
    *bucket = tgt->next;
    ah_bucket_free(tgt);
  } else {
    prev = tgt;
    tgt = tgt->next;
    while(((void *)0) != tgt)
    {
      if(strcmp(tgt->key, key) == 0) {
        prev->next = tgt->next;
        ah_bucket_free(tgt);
        return;
      }
      prev = tgt;
      tgt = tgt->next;
    }
  }
}

canonical_original_code:
void ah_bucket_remove(struct ah_t_bucket **bucket, char *key)
{
  struct ah_t_bucket *tgt = *bucket;
  struct ah_t_bucket *prev;
  if(((void *)0) == *bucket) return;
  if(strcmp(tgt->key, key) == 0) {
    *bucket = tgt->next;
    ah_bucket_free(tgt);
  } else {
    prev = tgt;
    tgt = tgt->next;
    while(((void *)0) != tgt)
    {
      if(strcmp(tgt->key, key) == 0) {
        prev->next = tgt->next;
        ah_bucket_free(tgt);
        return;
      }
      prev = tgt;
      tgt = tgt->next;
    }
  }
}


decompiled_code:
__int64 __fastcall ah_bucket_delete(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
result = ah_bucket_free(v2);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
result = func19(v2);
}
while ( v1 );
}
return result;
}

original_code:
void ah_bucket_delete(ah_bucket* bucket)
{
  if(bucket == ((void *)0)) return;
  ah_bucket* next = bucket->next;
  ah_bucket_free(bucket);
  ah_bucket_delete(next);
}

canonical_original_code:
void ah_bucket_delete(struct ah_t_bucket *bucket)
{
  if(bucket == ((void *)0)) return;
  struct ah_t_bucket *next = bucket->next;
  ah_bucket_free(bucket);
  ah_bucket_delete(next);
}


decompiled_code:
void *__fastcall ah_malloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Memory allocation error.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func24(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fwrite("Memory allocation error.\n", 1uLL, 0x19uLL, stderr);
exit(1);
}
return result;
}

original_code:
void* ah_malloc(ulong size)
{
  void* ptr = malloc(size);
  if(!ptr){
    fprintf(stderr, "Memory allocation error.\n");
    exit(1);
  }
  return ptr;
}

canonical_original_code:
void *ah_malloc(unsigned long size)
{
  void *ptr = malloc(size);
  if(!ptr){
    fprintf(stderr, "Memory allocation error.\n");
    exit(1);
  }
  return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


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

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

original_code:
void ah_free(void* ptr)
{
  if(ptr) {
    free(ptr);
  }
}

canonical_original_code:
void ah_free(void *ptr)
{
  if(ptr) {
    free(ptr);
  }
}


decompiled_code:
int __fastcall gen_random_key(char *a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // r15
void *v4; // rsp
char *v5; // r12
char *v6; // rdi
char v8[8]; // [rsp+0h] [rbp-40h] BYREF
char *s; // [rsp+8h] [rbp-38h]

v3 = a3 - 8;
s = a1;
v4 = alloca(16 * (((unsigned __int64)a3 + 15) >> 4));
if ( a3 != 8 )
{
v5 = v8;
do
*v5++ = rand() % 26 + 97;
while ( v5 != &v8[v3] );
}
v6 = s;
v8[v3] = 0;
return sprintf(v6, "%s%d", v8, a2);
}

canonical_decompiled_code:
int __fastcall func26(char *a1, unsigned int a2, unsigned int a3)
{
__int64 v3; // r15
void *v4; // rsp
char *v5; // r12
char *v6; // rdi
char v8[8]; // [rsp+0h] [rbp-40h] BYREF
char *s; // [rsp+8h] [rbp-38h]

v3 = a3 - 8;
s = a1;
v4 = alloca(16 * (((unsigned __int64)a3 + 15) >> 4));
if ( a3 != 8 )
{
v5 = v8;
do
*v5++ = rand() % 26 + 97;
while ( v5 != &v8[v3] );
}
v6 = s;
v8[v3] = 0;
return sprintf(v6, "%s%d", v8, a2);
}

original_code:
void gen_random_key(char* dst, uint k, uint len)
{
  char buff[len];
  uint i;
  for(i = 0; i < len-8; i++) {
    char c = (rand() % 26) + 97;
    buff[i] = c;
  }
  buff[i] = '\0';
  sprintf(dst, "%s%d", buff, k);
}

canonical_original_code:
void gen_random_key(char *dst, unsigned int k, unsigned int len)
{
  char buff[-1];
  unsigned int i;
  for(i = 0; i < len-8; i++) {
    char c = (rand() % 26) + 97;
    buff[i] = c;
  }
  buff[i] = '\0';
  sprintf(dst, "%s%d", buff, k);
}

variable_types:
dst
char *

variable_types:
k
unsigned int

variable_types:
len
unsigned int

variable_types:
buff
char [-1]

variable_types:
i
unsigned int

variable_types: c char


onDisplay

repo: rnentjes/OpenGL

decompiled_code:
__int64 onDisplay()
{
int v0; // ebp
float v1; // xmm3_4
double v2; // xmm3_8
unsigned int v3; // xmm2_4
float v4; // xmm3_4
double v5; // xmm5_8
double v6; // xmm4_8
unsigned int v7; // esi
double v8; // xmm2_8
double v9; // xmm0_8
double v10; // xmm2_8
double v11; // xmm3_8
__int128 v13; // [rsp+0h] [rbp-58h]
double v14; // [rsp+10h] [rbp-48h]
unsigned __int64 v15; // [rsp+20h] [rbp-38h]
__int128 cosx[2]; // [rsp+30h] [rbp-28h] BYREF

v0 = 100;
glClear(0x4000LL);
_glewUseProgram((unsigned int)program);
_glewActiveTexture(33984LL);
glBindTexture(3553LL, (unsigned int)texture_id);
_glewActiveTexture(33985LL);
glBindTexture(3553LL, (unsigned int)texture_id2);
_glewActiveTexture(33986LL);
glBindTexture(3553LL, (unsigned int)texture_id3);
v1 = (double)(int)(glutGet(700LL) - program_start) / 1000.0;
_glewBindBuffer(34962LL, (unsigned int)vbo_quad);
_glewVertexAttribPointer((unsigned int)attribute_coord2d, 2LL, 5126LL, 0LL, 0LL, 0LL);
_glewEnableVertexAttribArray((unsigned int)attribute_coord2d);
_glewBindBuffer(34963LL, (unsigned int)vbo_quad_elements);
v2 = v1;
do
{
*(float *)&v3 = (double)v0 / 1000.0 + (double)v0 / 1000.0;
v4 = v2 * 0.999;
sincos(v4, (double *)cosx + 1, (double *)cosx);
v13 = cosx[0];
v5 = *(double *)cosx * *(float *)&v3;
v14 = *(float *)&v3;
v6 = *((double *)cosx + 1) * *(float *)&v3;
*(float *)&v5 = v5;
*(float *)&v6 = v6;
v15 = __PAIR64__(LODWORD(v5), LODWORD(v6));
_glewUniform2f((unsigned int)uniform_location, v6, v5);
_glewUniform2f((unsigned int)uniform_size, COERCE_DOUBLE((unsigned __int64)v3), COERCE_DOUBLE((unsigned __int64)v3));
v7 = v0++;
_glewUniform1i((unsigned int)uniform_mytexture, v7 % 3);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
v8 = COERCE_DOUBLE(v13 ^ LC2) * *(float *)&v3;
v9 = COERCE_DOUBLE(*((_QWORD *)&v13 + 1) ^ LC2) * v14;
*(float *)&v8 = v8;
*(float *)&v9 = v9;
_glewUniform2f((unsigned int)uniform_location, v9, v8);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LODWORD(v9)),
COERCE_DOUBLE((unsigned __int64)HIDWORD(v15)));
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)(unsigned int)v15),
COERCE_DOUBLE((unsigned __int64)LODWORD(v8)));
glDrawElements(5LL, 4LL, 5123LL, 0LL);
v2 = v4;
}
while ( v0 != 500 );
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC3));
v10 = *((double *)&v13 + 1) + *((double *)&v13 + 1);
*(float *)&v10 = *((double *)&v13 + 1) + *((double *)&v13 + 1);
_glewUniform2f((unsigned int)uniform_size, v10, v10);
_glewUniform1i((unsigned int)uniform_mytexture, 0LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f((unsigned int)uniform_location, COERCE_DOUBLE((unsigned __int64)LC3), 0.0);
v11 = *(double *)&v13 + *(double *)&v13;
*(float *)&v11 = *(double *)&v13 + *(double *)&v13;
_glewUniform2f((unsigned int)uniform_size, v11, v11);
_glewUniform1i((unsigned int)uniform_mytexture, 1LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC5));
_glewUniform2f(
(unsigned int)uniform_size,
COERCE_DOUBLE((unsigned __int64)LODWORD(v10)),
COERCE_DOUBLE((unsigned __int64)LODWORD(v11)));
_glewUniform1i((unsigned int)uniform_mytexture, 2LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewDisableVertexAttribArray((unsigned int)attribute_coord2d);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebp
float v1; // xmm3_4
double v2; // xmm3_8
unsigned int v3; // xmm2_4
float v4; // xmm3_4
double v5; // xmm5_8
double v6; // xmm4_8
unsigned int v7; // esi
double v8; // xmm2_8
double v9; // xmm0_8
double v10; // xmm2_8
double v11; // xmm3_8
__int128 v13; // [rsp+0h] [rbp-58h]
double v14; // [rsp+10h] [rbp-48h]
unsigned __int64 v15; // [rsp+20h] [rbp-38h]
__int128 cosx[2]; // [rsp+30h] [rbp-28h] BYREF

v0 = 100;
glClear(0x4000LL);
_glewUseProgram((unsigned int)program);
_glewActiveTexture(33984LL);
glBindTexture(3553LL, (unsigned int)texture_id);
_glewActiveTexture(33985LL);
glBindTexture(3553LL, (unsigned int)texture_id2);
_glewActiveTexture(33986LL);
glBindTexture(3553LL, (unsigned int)texture_id3);
v1 = (double)(int)(glutGet(700LL) - program_start) / 1000.0;
_glewBindBuffer(34962LL, (unsigned int)vbo_quad);
_glewVertexAttribPointer((unsigned int)attribute_coord2d, 2LL, 5126LL, 0LL, 0LL, 0LL);
_glewEnableVertexAttribArray((unsigned int)attribute_coord2d);
_glewBindBuffer(34963LL, (unsigned int)vbo_quad_elements);
v2 = v1;
do
{
*(float *)&v3 = (double)v0 / 1000.0 + (double)v0 / 1000.0;
v4 = v2 * 0.999;
sincos(v4, (double *)cosx + 1, (double *)cosx);
v13 = cosx[0];
v5 = *(double *)cosx * *(float *)&v3;
v14 = *(float *)&v3;
v6 = *((double *)cosx + 1) * *(float *)&v3;
*(float *)&v5 = v5;
*(float *)&v6 = v6;
v15 = __PAIR64__(LODWORD(v5), LODWORD(v6));
_glewUniform2f((unsigned int)uniform_location, v6, v5);
_glewUniform2f((unsigned int)uniform_size, COERCE_DOUBLE((unsigned __int64)v3), COERCE_DOUBLE((unsigned __int64)v3));
v7 = v0++;
_glewUniform1i((unsigned int)uniform_mytexture, v7 % 3);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
v8 = COERCE_DOUBLE(v13 ^ LC2) * *(float *)&v3;
v9 = COERCE_DOUBLE(*((_QWORD *)&v13 + 1) ^ LC2) * v14;
*(float *)&v8 = v8;
*(float *)&v9 = v9;
_glewUniform2f((unsigned int)uniform_location, v9, v8);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LODWORD(v9)),
COERCE_DOUBLE((unsigned __int64)HIDWORD(v15)));
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)(unsigned int)v15),
COERCE_DOUBLE((unsigned __int64)LODWORD(v8)));
glDrawElements(5LL, 4LL, 5123LL, 0LL);
v2 = v4;
}
while ( v0 != 500 );
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC3));
v10 = *((double *)&v13 + 1) + *((double *)&v13 + 1);
*(float *)&v10 = *((double *)&v13 + 1) + *((double *)&v13 + 1);
_glewUniform2f((unsigned int)uniform_size, v10, v10);
_glewUniform1i((unsigned int)uniform_mytexture, 0LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f((unsigned int)uniform_location, COERCE_DOUBLE((unsigned __int64)LC3), 0.0);
v11 = *(double *)&v13 + *(double *)&v13;
*(float *)&v11 = *(double *)&v13 + *(double *)&v13;
_glewUniform2f((unsigned int)uniform_size, v11, v11);
_glewUniform1i((unsigned int)uniform_mytexture, 1LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewUniform2f(
(unsigned int)uniform_location,
COERCE_DOUBLE((unsigned __int64)LC3),
COERCE_DOUBLE((unsigned __int64)LC5));
_glewUniform2f(
(unsigned int)uniform_size,
COERCE_DOUBLE((unsigned __int64)LODWORD(v10)),
COERCE_DOUBLE((unsigned __int64)LODWORD(v11)));
_glewUniform1i((unsigned int)uniform_mytexture, 2LL);
glDrawElements(5LL, 4LL, 5123LL, 0LL);
_glewDisableVertexAttribArray((unsigned int)attribute_coord2d);
return glutSwapBuffers();
}

original_code:
void onDisplay() {
    glClear(0x00004000);
    __glewUseProgram(program);
    __glewActiveTexture(0x84C0);
    glBindTexture(0x0DE1, texture_id);
    __glewActiveTexture(0x84C1);
    glBindTexture(0x0DE1, texture_id2);
    __glewActiveTexture(0x84C2);
    glBindTexture(0x0DE1, texture_id3);
    GLfloat r = (glutGet(0x02BC) - program_start) / 1000.0;
    __glewBindBuffer(0x8892, vbo_quad);
    __glewVertexAttribPointer(
            attribute_coord2d,
            2,
            0x1406,
            0,
            0,
            0
            );
    __glewEnableVertexAttribArray(attribute_coord2d);
    __glewBindBuffer(0x8893, vbo_quad_elements);
    int i = 100;
    for (; i < 500; i++) {
      r = r * 0.999;
      GLfloat factor = (i/1000.0)*2.0;
      __glewUniform2f(uniform_location, sin(r) * factor, cos(r) * factor);
      __glewUniform2f(uniform_size, factor, factor);
      __glewUniform1i(uniform_mytexture, i % 3);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
    }
    __glewUniform2f(uniform_location, -0.5, -0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, sin(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 0);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.0);
    __glewUniform2f(uniform_size, cos(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 1);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 2);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewDisableVertexAttribArray(attribute_coord2d);
    glutSwapBuffers();
}

canonical_original_code:
void onDisplay() {
    glClear(0x00004000);
    __glewUseProgram(program);
    __glewActiveTexture(0x84C0);
    glBindTexture(0x0DE1, texture_id);
    __glewActiveTexture(0x84C1);
    glBindTexture(0x0DE1, texture_id2);
    __glewActiveTexture(0x84C2);
    glBindTexture(0x0DE1, texture_id3);
    float r = (glutGet(0x02BC) - program_start) / 1000.0;
    __glewBindBuffer(0x8892, vbo_quad);
    __glewVertexAttribPointer(
            attribute_coord2d,
            2,
            0x1406,
            0,
            0,
            0
            );
    __glewEnableVertexAttribArray(attribute_coord2d);
    __glewBindBuffer(0x8893, vbo_quad_elements);
    int i = 100;
    for (; i < 500; i++) {
      r = r * 0.999;
      float factor = (i/1000.0)*2.0;
      __glewUniform2f(uniform_location, sin(r) * factor, cos(r) * factor);
      __glewUniform2f(uniform_size, factor, factor);
      __glewUniform1i(uniform_mytexture, i % 3);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, -sin(r) * factor, cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
      __glewUniform2f(uniform_location, sin(r) * factor, -cos(r) * factor);
      glDrawElements(0x0005, 4, 0x1403, 0);
    }
    __glewUniform2f(uniform_location, -0.5, -0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, sin(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 0);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.0);
    __glewUniform2f(uniform_size, cos(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 1);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewUniform2f(uniform_location, -0.5, 0.5);
    __glewUniform2f(uniform_size, sin(r) * 2.0, cos(r) * 2.0);
    __glewUniform1i(uniform_mytexture, 2);
    glDrawElements(0x0005, 4, 0x1403, 0);
    __glewDisableVertexAttribArray(attribute_coord2d);
    glutSwapBuffers();
}

variable_types: r float

variable_types: i int

variable_types: factor float


idle

decompiled_code:
__int64 idle()
{
int v0; // eax

++fps_frames;
v0 = glutGet(700LL) - fps_start;
if ( v0 > 1000 )
{
fprintf(stdout, "FPS: %f\n", (double)fps_frames * 1000.0 / (double)v0);
fps_start += 1000;
fps_frames = 0;
}
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // eax

++fps_frames;
v0 = glutGet(700LL) - fps_start;
if ( v0 > 1000 )
{
fprintf(stdout, "FPS: %f\n", (double)fps_frames * 1000.0 / (double)v0);
fps_start += 1000;
fps_frames = 0;
}
return glutPostRedisplay();
}

original_code:
void idle() {
    fps_frames++;
    int delta_t = glutGet(0x02BC) - fps_start;
    if (delta_t > 1000) {
        fprintf(stdout, "FPS: %f\n", (1000.0 * fps_frames / delta_t));
        fps_frames = 0;
        fps_start = fps_start + 1000;
    }
    glutPostRedisplay();
}


decompiled_code:
__int64 init_resources()
{
unsigned int v0; // eax
__int64 result; // rax
unsigned int v2; // ebp
unsigned int v3; // er12
int v4; // [rsp+4h] [rbp-94h] BYREF
__int64 v5; // [rsp+8h] [rbp-90h] BYREF
__int64 v6[4]; // [rsp+10h] [rbp-88h] BYREF
__int64 v7[4]; // [rsp+30h] [rbp-68h] BYREF
__int64 v8[9]; // [rsp+50h] [rbp-48h] BYREF

v4 = 0;
fps_start = glutGet(700LL);
program_start = fps_start;
v0 = create_shader("triangle.v.glsl", 35633LL);
if ( !v0 )
return 0LL;
v2 = v0;
v3 = create_shader("triangle.f.glsl", 35632LL);
if ( !v3 )
return 0LL;
program = _glewCreateProgram();
_glewAttachShader((unsigned int)program, v2);
_glewAttachShader((unsigned int)program, v3);
_glewLinkProgram((unsigned int)program);
_glewGetProgramiv((unsigned int)program, 35714LL, &v4);
if ( !v4 )
{
fwrite("glLinkProgram:", 1uLL, 0xEuLL, stderr);
print_log((unsigned int)program);
}
texture_id = make_texture("glass.gif");
texture_id2 = make_texture("nehe.gif");
texture_id3 = make_texture("star.gif");
v6[0] = 0x3F4CCCCD00000000LL;
v6[1] = 0xBF4CCCCDBF4CCCCDLL;
v6[2] = 0xBF4CCCCD3F4CCCCDLL;
vbo_triangle = make_buffer(34962LL, v6, 24LL);
v7[0] = 0xBE4CCCCDBE4CCCCDLL;
v7[1] = 0xBE4CCCCD3E4CCCCDLL;
v7[2] = 0x3E4CCCCDBE4CCCCDLL;
v7[3] = 0x3E4CCCCD3E4CCCCDLL;
vbo_quad = make_buffer(34962LL, v7, 32LL);
v5 = 0x3000200010000LL;
vbo_quad_elements = make_buffer(34962LL, &v5, 8LL);
v8[0] = 0LL;
v8[1] = 1065353216LL;
v8[2] = 0x3F8000003F800000LL;
v8[3] = 0x3F8000003F800000LL;
v8[4] = 1065353216LL;
v8[5] = 0LL;
vbo_cube_texcoords = make_buffer(34962LL, v8, 48LL);
attribute_coord2d = _glewGetAttribLocation((unsigned int)program, "coord2d");
if ( attribute_coord2d == -1 )
{
fwrite("Could not bind attribute coord2d\n", 1uLL, 0x21uLL, stderr);
return 0LL;
}
uniform_mytexture = _glewGetUniformLocation((unsigned int)program, "mytexture");
if ( uniform_mytexture == -1 )
{
fwrite("Could not bind uniform mytexture\n", 1uLL, 0x21uLL, stderr);
return 0LL;
}
uniform_location = _glewGetUniformLocation((unsigned int)program, "location");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform location\n", 1uLL, 0x20uLL, stderr);
return 0LL;
}
uniform_size = _glewGetUniformLocation((unsigned int)program, "size");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform size\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
else
{
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glClearColor(0.0, 0.0, 0.0, 1.0);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // eax
__int64 result; // rax
unsigned int v2; // ebp
unsigned int v3; // er12
int v4; // [rsp+4h] [rbp-94h] BYREF
__int64 v5; // [rsp+8h] [rbp-90h] BYREF
__int64 v6[4]; // [rsp+10h] [rbp-88h] BYREF
__int64 v7[4]; // [rsp+30h] [rbp-68h] BYREF
__int64 v8[9]; // [rsp+50h] [rbp-48h] BYREF

v4 = 0;
fps_start = glutGet(700LL);
program_start = fps_start;
v0 = create_shader("triangle.v.glsl", 35633LL);
if ( !v0 )
return 0LL;
v2 = v0;
v3 = create_shader("triangle.f.glsl", 35632LL);
if ( !v3 )
return 0LL;
program = _glewCreateProgram();
_glewAttachShader((unsigned int)program, v2);
_glewAttachShader((unsigned int)program, v3);
_glewLinkProgram((unsigned int)program);
_glewGetProgramiv((unsigned int)program, 35714LL, &v4);
if ( !v4 )
{
fwrite("glLinkProgram:", 1uLL, 0xEuLL, stderr);
print_log((unsigned int)program);
}
texture_id = make_texture("glass.gif");
texture_id2 = make_texture("nehe.gif");
texture_id3 = make_texture("star.gif");
v6[0] = 0x3F4CCCCD00000000LL;
v6[1] = 0xBF4CCCCDBF4CCCCDLL;
v6[2] = 0xBF4CCCCD3F4CCCCDLL;
vbo_triangle = make_buffer(34962LL, v6, 24LL);
v7[0] = 0xBE4CCCCDBE4CCCCDLL;
v7[1] = 0xBE4CCCCD3E4CCCCDLL;
v7[2] = 0x3E4CCCCDBE4CCCCDLL;
v7[3] = 0x3E4CCCCD3E4CCCCDLL;
vbo_quad = make_buffer(34962LL, v7, 32LL);
v5 = 0x3000200010000LL;
vbo_quad_elements = make_buffer(34962LL, &v5, 8LL);
v8[0] = 0LL;
v8[1] = 1065353216LL;
v8[2] = 0x3F8000003F800000LL;
v8[3] = 0x3F8000003F800000LL;
v8[4] = 1065353216LL;
v8[5] = 0LL;
vbo_cube_texcoords = make_buffer(34962LL, v8, 48LL);
attribute_coord2d = _glewGetAttribLocation((unsigned int)program, "coord2d");
if ( attribute_coord2d == -1 )
{
fwrite("Could not bind attribute coord2d\n", 1uLL, 0x21uLL, stderr);
return 0LL;
}
uniform_mytexture = _glewGetUniformLocation((unsigned int)program, "mytexture");
if ( uniform_mytexture == -1 )
{
fwrite("Could not bind uniform mytexture\n", 1uLL, 0x21uLL, stderr);
return 0LL;
}
uniform_location = _glewGetUniformLocation((unsigned int)program, "location");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform location\n", 1uLL, 0x20uLL, stderr);
return 0LL;
}
uniform_size = _glewGetUniformLocation((unsigned int)program, "size");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform size\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
else
{
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glClearColor(0.0, 0.0, 0.0, 1.0);
result = 1LL;
}
return result;
}

original_code:
int init_resources() {
    GLint compile_ok = 0, link_ok = 0;
    program_start = fps_start = glutGet(0x02BC);
    GLuint vs, fs;
    if ((vs = create_shader("triangle.v.glsl", 0x8B31)) == 0) return 0;
    if ((fs = create_shader("triangle.f.glsl", 0x8B30)) == 0) return 0;
    program = __glewCreateProgram();
    __glewAttachShader(program, vs);
    __glewAttachShader(program, fs);
    __glewLinkProgram(program);
    __glewGetProgramiv(program, 0x8B82, &link_ok);
    if (!link_ok) {
        fprintf(stderr, "glLinkProgram:");
        print_log(program);
    }
    texture_id = make_texture("glass.gif");
    texture_id2 = make_texture("nehe.gif");
    texture_id3 = make_texture("star.gif");
    GLfloat triangle_vertices[] = {
        0.0, 0.8,
        -0.8, -0.8,
        0.8, -0.8,
    };
    vbo_triangle = make_buffer(0x8892, triangle_vertices, sizeof (triangle_vertices));
    GLfloat quad_vertices[] = {
        -0.2, -0.2,
         0.2, -0.2,
        -0.2, 0.2,
         0.2, 0.2,
    };
    vbo_quad = make_buffer(0x8892, quad_vertices, sizeof (quad_vertices));
    GLushort quad_elements[] = {
        0, 1, 2, 3,
    };
    vbo_quad_elements = make_buffer(0x8892, quad_elements, sizeof (quad_elements));
    GLfloat cube_texcoords[] = {
        0.0, 0.0,
        1.0, 0.0,
        1.0, 1.0,
        1.0, 1.0,
        1.0, 0.0,
        0.0, 0.0,
    };
    vbo_cube_texcoords = make_buffer(0x8892, cube_texcoords, sizeof (cube_texcoords));
    attribute_coord2d = __glewGetAttribLocation(program, "coord2d");
    if (attribute_coord2d == -1) {
        fprintf(stderr, "Could not bind attribute coord2d\n");
        return 0;
    }
    uniform_mytexture = __glewGetUniformLocation(program, "mytexture");
    if (uniform_mytexture == -1) {
        fprintf(stderr, "Could not bind uniform mytexture\n");
        return 0;
    }
    uniform_location = __glewGetUniformLocation(program, "location");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform location\n");
        return 0;
    }
    uniform_size = __glewGetUniformLocation(program, "size");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform size\n");
        return 0;
    }
    glEnable(0x0BE2);
    glBlendFunc(0x0302, 0x0303);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    return 1;
}

canonical_original_code:
int init_resources() {
    int compile_ok = 0; int link_ok = 0;
    program_start = fps_start = glutGet(0x02BC);
    unsigned int vs; unsigned int fs;
    if ((vs = create_shader("triangle.v.glsl", 0x8B31)) == 0) return 0;
    if ((fs = create_shader("triangle.f.glsl", 0x8B30)) == 0) return 0;
    program = __glewCreateProgram();
    __glewAttachShader(program, vs);
    __glewAttachShader(program, fs);
    __glewLinkProgram(program);
    __glewGetProgramiv(program, 0x8B82, &link_ok);
    if (!link_ok) {
        fprintf(stderr, "glLinkProgram:");
        print_log(program);
    }
    texture_id = make_texture("glass.gif");
    texture_id2 = make_texture("nehe.gif");
    texture_id3 = make_texture("star.gif");
    float triangle_vertices[] = {
        0.0, 0.8,
        -0.8, -0.8,
        0.8, -0.8,
    };
    vbo_triangle = make_buffer(0x8892, triangle_vertices, sizeof (triangle_vertices));
    float quad_vertices[] = {
        -0.2, -0.2,
         0.2, -0.2,
        -0.2, 0.2,
         0.2, 0.2,
    };
    vbo_quad = make_buffer(0x8892, quad_vertices, sizeof (quad_vertices));
    unsigned short quad_elements[] = {
        0, 1, 2, 3,
    };
    vbo_quad_elements = make_buffer(0x8892, quad_elements, sizeof (quad_elements));
    float cube_texcoords[] = {
        0.0, 0.0,
        1.0, 0.0,
        1.0, 1.0,
        1.0, 1.0,
        1.0, 0.0,
        0.0, 0.0,
    };
    vbo_cube_texcoords = make_buffer(0x8892, cube_texcoords, sizeof (cube_texcoords));
    attribute_coord2d = __glewGetAttribLocation(program, "coord2d");
    if (attribute_coord2d == -1) {
        fprintf(stderr, "Could not bind attribute coord2d\n");
        return 0;
    }
    uniform_mytexture = __glewGetUniformLocation(program, "mytexture");
    if (uniform_mytexture == -1) {
        fprintf(stderr, "Could not bind uniform mytexture\n");
        return 0;
    }
    uniform_location = __glewGetUniformLocation(program, "location");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform location\n");
        return 0;
    }
    uniform_size = __glewGetUniformLocation(program, "size");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform size\n");
        return 0;
    }
    glEnable(0x0BE2);
    glBlendFunc(0x0302, 0x0303);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    return 1;
}

variable_types:
vs
unsigned int

variable_types:
fs
unsigned int

return_type: int


decompiled_code:
__int64 free_resources()
{
_glewDeleteProgram((unsigned int)program);
_glewDeleteBuffers(1LL, &vbo_triangle);
_glewDeleteBuffers(1LL, &vbo_quad);
return glDeleteTextures(1LL, &texture_id);
}

canonical_decompiled_code:
__int64 func3()
{
_glewDeleteProgram((unsigned int)program);
_glewDeleteBuffers(1LL, &vbo_triangle);
_glewDeleteBuffers(1LL, &vbo_quad);
return glDeleteTextures(1LL, &texture_id);
}

original_code:
void free_resources() {
    __glewDeleteProgram(program);
    __glewDeleteBuffers(1, &vbo_triangle);
    __glewDeleteBuffers(1, &vbo_quad);
    glDeleteTextures(1, &texture_id);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int result; // eax
const char *v5; // rax
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = argc;
glutInit(v6, argv, envp);
glutInitDisplayMode(26LL);
glutInitWindowSize(1000LL, 800LL);
glutCreateWindow("My First Triangle");
v3 = glewInit();
if ( v3 )
{
v5 = (const char *)glewGetErrorString(v3);
fprintf(stderr, "Error: %s\n", v5);
result = 1;
}
else
{
if ( (unsigned int)init_resources() )
{
glutDisplayFunc(onDisplay);
glutIdleFunc(idle);
glutMainLoop();
}
free_resources();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int result; // eax
const char *v5; // rax
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = argc;
glutInit(v6, argv, envp);
glutInitDisplayMode(26LL);
glutInitWindowSize(1000LL, 800LL);
glutCreateWindow("My First Triangle");
v3 = glewInit();
if ( v3 )
{
v5 = (const char *)glewGetErrorString(v3);
fprintf(stderr, "Error: %s\n", v5);
result = 1;
}
else
{
if ( (unsigned int)func2() )
{
glutDisplayFunc(onDisplay);
glutIdleFunc(idle);
glutMainLoop();
}
func3();
result = 0;
}
return result;
}

original_code:
int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0000 | 0x0008 | 0x0002 | 0x0010);
    glutInitWindowSize(1000, 800);
    glutCreateWindow("My First Triangle");
    GLenum glew_status = glewInit();
    if (glew_status != 0) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
        return 1;
    }
    if (init_resources()) {
        glutDisplayFunc(onDisplay);
        glutIdleFunc(idle);
        glutMainLoop();
    }
    free_resources();
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0000 | 0x0008 | 0x0002 | 0x0010);
    glutInitWindowSize(1000, 800);
    glutCreateWindow("My First Triangle");
    unsigned int glew_status = glewInit();
    if (glew_status != 0) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
        return 1;
    }
    if (init_resources()) {
        glutDisplayFunc(onDisplay);
        glutIdleFunc(idle);
        glutMainLoop();
    }
    free_resources();
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall le_short(unsigned __int16 *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1)
{
return *a1;
}

original_code:
static short le_short(unsigned char *bytes) {
    return bytes[0] | ((char) bytes[1] << 8);
}

variable_types:
bytes
unsigned char *

return_type: short


decompiled_code:
void __fastcall print_log(unsigned int a1)
{
char *v1; // r12
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2[0] = 0;
if ( (unsigned __int8)((__int64 (*)(void))_glewIsShader)() )
{
_glewGetShaderiv(a1, 35716LL, v2);
}
else
{
if ( !(unsigned __int8)_glewIsProgram(a1) )
{
fwrite("printlog: Not a shader or a program\n", 1uLL, 0x24uLL, stderr);
return;
}
_glewGetProgramiv(a1, 35716LL, v2);
}
v1 = (char *)malloc(v2[0]);
if ( (unsigned __int8)_glewIsShader(a1) )
{
_glewGetShaderInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
else if ( (unsigned __int8)_glewIsProgram(a1) )
{
_glewGetProgramInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
fputs(v1, stderr);
free(v1);
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1)
{
char *v1; // r12
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2[0] = 0;
if ( (unsigned __int8)((__int64 (*)(void))_glewIsShader)() )
{
_glewGetShaderiv(a1, 35716LL, v2);
}
else
{
if ( !(unsigned __int8)_glewIsProgram(a1) )
{
fwrite("printlog: Not a shader or a program\n", 1uLL, 0x24uLL, stderr);
return;
}
_glewGetProgramiv(a1, 35716LL, v2);
}
v1 = (char *)malloc(v2[0]);
if ( (unsigned __int8)_glewIsShader(a1) )
{
_glewGetShaderInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
else if ( (unsigned __int8)_glewIsProgram(a1) )
{
_glewGetProgramInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
fputs(v1, stderr);
free(v1);
}

original_code:
void print_log(GLuint object) {
    GLint log_length = 0;
    if (__glewIsShader(object))
        __glewGetShaderiv(object, 0x8B84, &log_length);
    else if (__glewIsProgram(object))
        __glewGetProgramiv(object, 0x8B84, &log_length);
    else {
        fprintf(stderr, "printlog: Not a shader or a program\n");
        return;
    }
    char* log = (char*) malloc(log_length);
    if (__glewIsShader(object))
        __glewGetShaderInfoLog(object, log_length, ((void *)0), log);
    else if (__glewIsProgram(object))
        __glewGetProgramInfoLog(object, log_length, ((void *)0), log);
    fprintf(stderr, "%s", log);
    free(log);
}

canonical_original_code:
void print_log(unsigned int object) {
    int log_length = 0;
    if (__glewIsShader(object))
        __glewGetShaderiv(object, 0x8B84, &log_length);
    else if (__glewIsProgram(object))
        __glewGetProgramiv(object, 0x8B84, &log_length);
    else {
        fprintf(stderr, "printlog: Not a shader or a program\n");
        return;
    }
    char *log = (char*) malloc(log_length);
    if (__glewIsShader(object))
        __glewGetShaderInfoLog(object, log_length, ((void *)0), log);
    else if (__glewIsProgram(object))
        __glewGetProgramInfoLog(object, log_length, ((void *)0), log);
    fprintf(stderr, "%s", log);
    free(log);
}

variable_types:
object
unsigned int

variable_types:
log
char *


decompiled_code:
__int64 __fastcall create_shader(const char *a1, unsigned int a2)
{
__int64 v2; // r12
int v4; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = file_read(a1);
if ( !ptr )
{
LODWORD(v2) = 0;
fprintf(stderr, "Error opening %s: ", a1);
perror(&s);
return (unsigned int)v2;
}
v2 = (unsigned int)_glewCreateShader(a2);
_glewShaderSource(v2, 1LL, &ptr, 0LL);
free(ptr);
_glewCompileShader((unsigned int)v2);
v4 = 0;
_glewGetShaderiv((unsigned int)v2, 35713LL, &v4);
if ( v4 )
return (unsigned int)v2;
fprintf(stderr, "%s:", a1);
print_log(v2);
_glewDeleteShader((unsigned int)v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, unsigned int a2)
{
__int64 v2; // r12
int v4; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = file_read(a1);
if ( !ptr )
{
LODWORD(v2) = 0;
fprintf(stderr, "Error opening %s: ", a1);
perror(&s);
return (unsigned int)v2;
}
v2 = (unsigned int)_glewCreateShader(a2);
_glewShaderSource(v2, 1LL, &ptr, 0LL);
free(ptr);
_glewCompileShader((unsigned int)v2);
v4 = 0;
_glewGetShaderiv((unsigned int)v2, 35713LL, &v4);
if ( v4 )
return (unsigned int)v2;
fprintf(stderr, "%s:", a1);
func1(v2);
_glewDeleteShader((unsigned int)v2);
return 0LL;
}

original_code:
GLuint create_shader(const char* filename, GLenum type) {
    const GLchar* source = file_read(filename);
    if (source == ((void *)0)) {
        fprintf(stderr, "Error opening %s: ", filename);
        perror("");
        return 0;
    }
    GLuint res = __glewCreateShader(type);
    __glewShaderSource(res, 1, &source, ((void *)0));
    free((void*) source);
    __glewCompileShader(res);
    GLint compile_ok = 0;
    __glewGetShaderiv(res, 0x8B81, &compile_ok);
    if (compile_ok == 0) {
        fprintf(stderr, "%s:", filename);
        print_log(res);
        __glewDeleteShader(res);
        return 0;
    }
    return res;
}

canonical_original_code:
unsigned int create_shader(char *filename, unsigned int type) {
    char *source = file_read(filename);
    if (source == ((void *)0)) {
        fprintf(stderr, "Error opening %s: ", filename);
        perror("");
        return 0;
    }
    unsigned int res = __glewCreateShader(type);
    __glewShaderSource(res, 1, &source, ((void *)0));
    free((void *) source);
    __glewCompileShader(res);
    int compile_ok = 0;
    __glewGetShaderiv(res, 0x8B81, &compile_ok);
    if (compile_ok == 0) {
        fprintf(stderr, "%s:", filename);
        print_log(res);
        __glewDeleteShader(res);
        return 0;
    }
    return res;
}

variable_types:
filename
char *

variable_types:
type
unsigned int

variable_types:
source
char *

variable_types:
res
unsigned int


decompiled_code:
__int64 __fastcall make_buffer(unsigned int a1, __int64 a2, int a3)
{
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_glewGenBuffers(1LL, v5);
_glewBindBuffer(a1, v5[0]);
_glewBufferData(a1, a3, a2, 35044LL);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, int a3)
{
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_glewGenBuffers(1LL, v5);
_glewBindBuffer(a1, v5[0]);
_glewBufferData(a1, a3, a2, 35044LL);
return v5[0];
}

original_code:
GLuint make_buffer(
        GLenum target,
        const void *buffer_data,
        GLsizei buffer_size
        ) {
    GLuint buffer;
    __glewGenBuffers(1, &buffer);
    __glewBindBuffer(target, buffer);
    __glewBufferData(target, buffer_size, buffer_data, 0x88E4);
    return buffer;
}

canonical_original_code:
unsigned int make_buffer(unsigned int target, void *buffer_data, int buffer_size) {
    unsigned int buffer;
    __glewGenBuffers(1, &buffer);
    __glewBindBuffer(target, buffer);
    __glewBufferData(target, buffer_size, buffer_data, 0x88E4);
    return buffer;
}

variable_types:
target
unsigned int

variable_types:
buffer
unsigned int


decompiled_code:
__int64 __fastcall make_texture_old(const char *a1)
{
void *v1; // rbp
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = read_tga(a1, &v3, &v4);
result = 0LL;
if ( v1 )
{
glGenTextures(1LL, v5);
glBindTexture(3553LL, v5[0]);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
glTexParameteri(3553LL, 10242LL, 33071LL);
glTexParameteri(3553LL, 10243LL, 33071LL);
glTexImage2D(3553LL, 0LL, 32849LL, v3, v4, 0LL, 32992LL, 5121LL, v1);
free(v1);
result = v5[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
void *v1; // rbp
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = func5(a1, &v3, &v4);
result = 0LL;
if ( v1 )
{
glGenTextures(1LL, v5);
glBindTexture(3553LL, v5[0]);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
glTexParameteri(3553LL, 10242LL, 33071LL);
glTexParameteri(3553LL, 10243LL, 33071LL);
glTexImage2D(3553LL, 0LL, 32849LL, v3, v4, 0LL, 32992LL, 5121LL, v1);
free(v1);
result = v5[0];
}
return result;
}

original_code:
GLuint make_texture_old(const char *filename) {
    int width, height;
    void *pixels = read_tga(filename, &width, &height);
    GLuint texture;
    if (!pixels)
        return 0;
    glGenTextures(1, &texture);
    glBindTexture(0x0DE1, texture);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2802, 0x812F);
    glTexParameteri(0x0DE1, 0x2803, 0x812F);
    glTexImage2D(
            0x0DE1, 0,
            0x8051,
            width, height, 0,
            0x80E0, 0x1401,
            pixels
            );
    free(pixels);
    return texture;
}

canonical_original_code:
unsigned int make_texture_old(char *filename) {
    int width; int height;
    void *pixels = read_tga(filename, &width, &height);
    unsigned int texture;
    if (!pixels)
        return 0;
    glGenTextures(1, &texture);
    glBindTexture(0x0DE1, texture);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2802, 0x812F);
    glTexParameteri(0x0DE1, 0x2803, 0x812F);
    glTexImage2D(
            0x0DE1, 0,
            0x8051,
            width, height, 0,
            0x80E0, 0x1401,
            pixels
            );
    free(pixels);
    return texture;
}

variable_types: width int

variable_types: height int

variable_types:
pixels
void *

variable_types:
texture
unsigned int


decompiled_code:
__int64 __fastcall make_texture(const char *a1)
{
unsigned int v1; // eax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbx
unsigned int v6; // er12
unsigned int v7; // eax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = FreeImage_GetFileType(a1, 0LL);
v2 = FreeImage_Load(v1, a1, 0LL);
v3 = FreeImage_ConvertTo32Bits(v2);
if ( v3 )
{
v4 = v3;
glGenTextures(1LL, v9);
glBindTexture(3553LL, v9[0]);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
v5 = FreeImage_GetBits(v4);
v6 = FreeImage_GetHeight(v4);
v7 = FreeImage_GetWidth(v4);
glTexImage2D(3553LL, 0LL, 4LL, v7, v6, 0LL, 32993LL, 5121LL, v5);
FreeImage_Unload(v4);
}
else
{
fprintf(stderr, "Can't load texture: %s\n", a1);
}
return v9[0];
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned int v1; // eax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbp
__int64 v5; // rbx
unsigned int v6; // er12
unsigned int v7; // eax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = FreeImage_GetFileType(a1, 0LL);
v2 = FreeImage_Load(v1, a1, 0LL);
v3 = FreeImage_ConvertTo32Bits(v2);
if ( v3 )
{
v4 = v3;
glGenTextures(1LL, v9);
glBindTexture(3553LL, v9[0]);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
v5 = FreeImage_GetBits(v4);
v6 = FreeImage_GetHeight(v4);
v7 = FreeImage_GetWidth(v4);
glTexImage2D(3553LL, 0LL, 4LL, v7, v6, 0LL, 32993LL, 5121LL, v5);
FreeImage_Unload(v4);
}
else
{
fprintf(stderr, "Can't load texture: %s\n", a1);
}
return v9[0];
}

original_code:
GLuint make_texture(const char *filename) {
    GLuint texture;
    FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(filename, 0);
    FIBITMAP *dib = FreeImage_Load(fifmt, filename, 0);
    dib = FreeImage_ConvertTo32Bits(dib);
    if (dib != ((void *)0)) {
        glGenTextures(1, &texture);
        glBindTexture(0x0DE1, texture);
        glTexParameteri(0x0DE1, 0x2801, 0x2601);
        glTexParameteri(0x0DE1, 0x2800, 0x2601);
        BYTE *pixels = (BYTE*) FreeImage_GetBits(dib);
        glTexImage2D(0x0DE1, 0, 4, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,
                0x80E1, 0x1401, pixels);
        FreeImage_Unload(dib);
    } else {
        fprintf(stderr, "Can't load texture: %s\n", filename);
    }
    return texture;
}

canonical_original_code:
unsigned int make_texture(char *filename) {
    unsigned int texture;
    int fifmt = FreeImage_GetFileType(filename, 0);
    struct FIBITMAP *dib = FreeImage_Load(fifmt, filename, 0);
    dib = FreeImage_ConvertTo32Bits(dib);
    if (dib != ((void *)0)) {
        glGenTextures(1, &texture);
        glBindTexture(0x0DE1, texture);
        glTexParameteri(0x0DE1, 0x2801, 0x2601);
        glTexParameteri(0x0DE1, 0x2800, 0x2601);
        unsigned char *pixels = (BYTE*) FreeImage_GetBits(dib);
        glTexImage2D(0x0DE1, 0, 4, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,
                0x80E1, 0x1401, pixels);
        FreeImage_Unload(dib);
    } else {
        fprintf(stderr, "Can't load texture: %s\n", filename);
    }
    return texture;
}

variable_types: fifmt int

variable_types:
dib
struct FIBITMAP { void *data; } *

variable_types:
pixels
unsigned char *


hardwareInit

repo: rnestler/heligame

decompiled_code:
__int64 hardwareInit()
{
unsigned int v0; // eax
__int64 result; // rax

if ( (int)SDL_Init(32LL) < 0 )
exit(1);
atexit((void (*)(void))&SDL_Quit);
if ( (int)TTF_Init() < 0 )
exit(2);
atexit((void (*)(void))&TTF_Quit);
font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 16LL);
if ( !font )
exit(3);
v0 = TTF_FontLineSkip(font);
printf("The font line skip is: %d\n", v0);
result = SDL_SetVideoMode(320LL, 160LL, 16LL, 0LL);
screen = result;
return result;
}

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

if ( (int)SDL_Init(32LL) < 0 )
exit(1);
atexit((void (*)(void))&SDL_Quit);
if ( (int)TTF_Init() < 0 )
exit(2);
atexit((void (*)(void))&TTF_Quit);
font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 16LL);
if ( !font )
exit(3);
v0 = TTF_FontLineSkip(font);
printf("The font line skip is: %d\n", v0);
result = SDL_SetVideoMode(320LL, 160LL, 16LL, 0LL);
screen = result;
return result;
}

original_code:
void hardwareInit()
{
 if(SDL_Init(0x00000020)<0) {
  exit(1);
 }
 atexit(SDL_Quit);
 if(TTF_Init() < 0) {
  exit(2);
 }
 atexit(TTF_Quit);
 font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 8*2);
 if(!font) {
  exit(3);
 }
 printf("The font line skip is: %d\n", TTF_FontLineSkip(font));
 Uint32 flags = 0x00000000;
 screen = SDL_SetVideoMode(160*2, 80*2, 16, flags);
}

canonical_original_code:
void hardwareInit()
{
 if(SDL_Init(0x00000020)<0) {
  exit(1);
 }
 atexit(SDL_Quit);
 if(TTF_Init() < 0) {
  exit(2);
 }
 atexit(TTF_Quit);
 font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 8*2);
 if(!font) {
  exit(3);
 }
 printf("The font line skip is: %d\n", TTF_FontLineSkip(font));
 unsigned int flags = 0x00000000;
 screen = SDL_SetVideoMode(160*2, 80*2, 16, flags);
}

variable_types:
flags
unsigned int


DelayMs

decompiled_code:
// attributes: thunk
__int64 DelayMs()
{
return SDL_Delay();
}

canonical_decompiled_code:
__int64 func3()
{
return SDL_Delay();
}

original_code:
void DelayMs (int ms)
{
 SDL_Delay(ms);
}

canonical_original_code:
void DelayMs(int ms)
{
 SDL_Delay(ms);
}

variable_types: ms int


DisplayClrArea

decompiled_code:
__int64 __fastcall DisplayClrArea(__int16 a1, __int16 a2, __int16 a3, __int16 a4)
{
__int16 v5[8]; // [rsp+8h] [rbp-10h] BYREF

v5[0] = a1;
v5[1] = a2;
v5[2] = 2 * a3;
v5[3] = 2 * a4;
SDL_FillRect(screen, v5, 0LL);
return SDL_UpdateRect(screen, 0LL, 0LL, 320LL, 160LL);
}

original_code:
void DisplayClrArea (int x_start, int y_start, int x_end, int y_end)
{
 SDL_Rect rect;
 rect.x = x_start;
 rect.y = y_start;
 rect.w = x_end*2;
 rect.h = y_end*2;
 SDL_FillRect(screen, &rect, 0x000000);
 SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}

canonical_original_code:
void DisplayClrArea(int x_start, int y_start, int x_end, int y_end)
{
 struct SDL_Rect rect;
 rect.x = x_start;
 rect.y = y_start;
 rect.w = x_end*2;
 rect.h = y_end*2;
 SDL_FillRect(screen, &rect, 0x000000);
 SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}

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


DisplaySetPoint

decompiled_code:
__int64 __fastcall DisplaySetPoint(__int16 a1, __int16 a2)
{
__int16 v3[2]; // [rsp+8h] [rbp-10h] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

v3[0] = 2 * a1;
v4 = 131074;
v3[1] = 2 * (80 - a2);
return SDL_FillRect(screen, v3, 0xFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1, __int16 a2)
{
__int16 v3[2]; // [rsp+8h] [rbp-10h] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

v3[0] = 2 * a1;
v4 = 131074;
v3[1] = 2 * (80 - a2);
return SDL_FillRect(screen, v3, 0xFFFFFFLL);
}

original_code:
int DisplaySetPoint (int x, int y)
{
 SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0xFFFFFF);
}

canonical_original_code:
int DisplaySetPoint(int x, int y)
{
 struct SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0xFFFFFF);
}

variable_types: x int

variable_types: y int

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


DisplayClrPoint

decompiled_code:
__int64 __fastcall DisplayClrPoint(__int16 a1, __int16 a2)
{
__int16 v3[2]; // [rsp+8h] [rbp-10h] BYREF
int v4; // [rsp+Ch] [rbp-Ch]

v3[0] = 2 * a1;
v4 = 131074;
v3[1] = 2 * (80 - a2);
return SDL_FillRect(screen, v3, 0LL);
}

original_code:
int DisplayClrPoint (int x, int y)
{
 SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0x000000);
}

canonical_original_code:
int DisplayClrPoint(int x, int y)
{
 struct SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0x000000);
}


DisplayDrawCircle

decompiled_code:
__int64 __fastcall DisplayDrawCircle(__int16 a1, __int16 a2, int a3)
{
int v3; // ebp
__int16 v4; // r12
int v5; // er15
__int16 v6; // r14
int i; // ebx
int v9; // [rsp+1Ch] [rbp-3Ch]

v3 = a3;
v4 = a3 + a2;
v5 = 1 - a3;
v6 = a3 + a1;
v9 = -2 * a3;
DisplaySetPoint(a1, a3 + a2);
DisplaySetPoint(a1, a2 - v3);
DisplaySetPoint(v6, a2);
DisplaySetPoint(a1 - v3, a2);
if ( v3 > 0 )
{
for ( i = 0; i < v3; DisplaySetPoint(a1 - v3, a2 - i) )
{
if ( v5 >= 0 )
{
v9 += 2;
v4 = --v3 + a2;
v5 += v9;
v6 = v3 + a1;
}
++i;
v5 += 2 * i + 1;
DisplaySetPoint(a1 + i, v4);
DisplaySetPoint(a1 - i, v4);
DisplaySetPoint(a1 + i, a2 - v3);
DisplaySetPoint(a1 - i, a2 - v3);
DisplaySetPoint(v6, i + a2);
DisplaySetPoint(a1 - v3, i + a2);
DisplaySetPoint(v6, a2 - i);
}
}
return SDL_UpdateRect(screen, 0LL, 0LL, 320LL, 160LL);
}

original_code:
void DisplayDrawCircle(int x0, int y0, int radius)
{
    int f = 1 - radius;
    int ddF_x = 0;
    int ddF_y = -2 * radius;
    int x = 0;
    int y = radius;
    DisplaySetPoint(x0, y0 + radius);
    DisplaySetPoint(x0, y0 - radius);
    DisplaySetPoint(x0 + radius, y0);
    DisplaySetPoint(x0 - radius, y0);
    while(x < y)
    {
       if(f >= 0)
       {
          y--;
          ddF_y += 2;
          f += ddF_y;
       }
       x++;
       ddF_x += 2;
       f += ddF_x + 1;
       DisplaySetPoint(x0 + x, y0 + y);
       DisplaySetPoint(x0 - x, y0 + y);
       DisplaySetPoint(x0 + x, y0 - y);
       DisplaySetPoint(x0 - x, y0 - y);
       DisplaySetPoint(x0 + y, y0 + x);
       DisplaySetPoint(x0 - y, y0 + x);
       DisplaySetPoint(x0 + y, y0 - x);
       DisplaySetPoint(x0 - y, y0 - x);
    }
 SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}

variable_types: radius int

variable_types: f int


DisplayClearCircle

decompiled_code:
__int64 __fastcall DisplayClearCircle(__int16 a1, __int16 a2, int a3)
{
int v3; // ebp
__int16 v4; // r12
int v5; // er15
__int16 v6; // r14
__int64 result; // rax
int i; // ebx
int v9; // [rsp+1Ch] [rbp-3Ch]

v3 = a3;
v4 = a3 + a2;
v5 = 1 - a3;
v6 = a3 + a1;
v9 = -2 * a3;
DisplayClrPoint(a1, a3 + a2);
DisplayClrPoint(a1, a2 - v3);
DisplayClrPoint(v6, a2);
result = DisplayClrPoint(a1 - (unsigned __int16)v3, a2);
if ( v3 > 0 )
{
for ( i = 0; i < v3; result = DisplayClrPoint(a1 - (unsigned __int16)v3, a2 - (unsigned __int16)i) )
{
if ( v5 >= 0 )
{
v9 += 2;
v4 = --v3 + a2;
v5 += v9;
v6 = v3 + a1;
}
++i;
v5 += 2 * i + 1;
DisplayClrPoint(a1 + i, v4);
DisplayClrPoint(a1 - i, v4);
DisplayClrPoint(a1 + i, a2 - v3);
DisplayClrPoint(a1 - i, a2 - v3);
DisplayClrPoint(v6, i + a2);
DisplayClrPoint(a1 - v3, i + a2);
DisplayClrPoint(v6, a2 - i);
}
}
return result;
}

original_code:
void DisplayClearCircle(int x0, int y0, int radius)
{
    int f = 1 - radius;
    int ddF_x = 0;
    int ddF_y = -2 * radius;
    int x = 0;
    int y = radius;
    DisplayClrPoint(x0, y0 + radius);
    DisplayClrPoint(x0, y0 - radius);
    DisplayClrPoint(x0 + radius, y0);
    DisplayClrPoint(x0 - radius, y0);
    while(x < y)
    {
       if(f >= 0)
       {
          y--;
          ddF_y += 2;
          f += ddF_y;
       }
       x++;
       ddF_x += 2;
       f += ddF_x + 1;
       DisplayClrPoint(x0 + x, y0 + y);
       DisplayClrPoint(x0 - x, y0 + y);
       DisplayClrPoint(x0 + x, y0 - y);
       DisplayClrPoint(x0 - x, y0 - y);
       DisplayClrPoint(x0 + y, y0 + x);
       DisplayClrPoint(x0 - y, y0 + x);
       DisplayClrPoint(x0 + y, y0 - x);
       DisplayClrPoint(x0 - y, y0 - x);
    }
}


DisplayDrawLine

decompiled_code:
__int64 __fastcall DisplayDrawLine(int a1, int a2, int a3, int a4)
{
int v4; // er14
__int16 v5; // bp
__int16 v6; // bx
signed int v7; // er12
signed int v8; // er15
int v9; // er13
int v10; // er13
signed int v11; // er12
__int16 v12; // si
__int64 result; // rax
signed int v14; // er13
__int16 v15; // di
int i; // er12
__int16 v17; // si
int v18; // er15
int v19; // eax
__int16 v20; // di
int v21; // [rsp+Ch] [rbp-3Ch]

v4 = a4 - a2;
v5 = a2;
v6 = a1;
if ( a3 == a1 )
{
for ( i = 0; v4 >= i; result = DisplaySetPoint(a1, v17) )
v17 = i++ + v5;
}
else
{
v21 = a3 - a1;
v7 = abs32(a3 - a1);
if ( a4 == a2 )
{
v14 = 0;
do
{
v15 = v14++ + v6;
result = DisplaySetPoint(v15, a2);
}
while ( v7 >= v14 );
}
else
{
v8 = abs32(v4);
v9 = v8 / v7;
if ( v8 / v7 )
{
if ( a4 < a2 )
{
v5 = a4;
v21 = a1 - a3;
v6 = a3;
}
v10 = 0;
v11 = 0;
do
{
v12 = v11++ + v5;
result = DisplaySetPoint((unsigned __int16)(v10 / v8) + v6, v12);
v10 += v21;
}
while ( v8 >= v11 );
}
else
{
if ( a3 < a1 )
{
v6 = a3;
v5 = a4;
v4 = a2 - a4;
}
v18 = 0;
do
{
v19 = v18;
v20 = v9++ + v6;
v18 += v4;
result = DisplaySetPoint(v20, (unsigned __int16)(v19 / v7) + v5);
}
while ( v7 >= v9 );
}
}
}
return result;
}

original_code:
void DisplayDrawLine (int x_start, int y_start, int x_end, int y_end)
{
 int x, y, temp, delta_x, delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplaySetPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplaySetPoint(x+x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for(y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplaySetPoint(x, y_start + y);
  }
 }
 else
  {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
  }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplaySetPoint(x_start + x, y);
  }
 }
}

canonical_original_code:
void DisplayDrawLine(int x_start, int y_start, int x_end, int y_end)
{
 int x; int y; int temp; int delta_x; int delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplaySetPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplaySetPoint(x+x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for(y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplaySetPoint(x, y_start + y);
  }
 }
 else
  {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
  }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplaySetPoint(x_start + x, y);
  }
 }
}

variable_types: temp int


DisplayClrLine

decompiled_code:
__int64 __fastcall DisplayClrLine(int a1, int a2, int a3, int a4)
{
int v4; // er14
__int16 v5; // bp
__int16 v6; // bx
signed int v7; // er12
signed int v8; // er15
int v9; // er13
int v10; // er13
signed int v11; // er12
__int16 v12; // si
__int64 result; // rax
signed int v14; // er13
__int16 v15; // di
int i; // er12
__int16 v17; // si
int v18; // er15
int v19; // eax
__int16 v20; // di
int v21; // [rsp+Ch] [rbp-3Ch]

v4 = a4 - a2;
v5 = a2;
v6 = a1;
if ( a3 == a1 )
{
for ( i = 0; v4 >= i; result = DisplayClrPoint(a1, v17) )
v17 = i++ + v5;
}
else
{
v21 = a3 - a1;
v7 = abs32(a3 - a1);
if ( a4 == a2 )
{
v14 = 0;
do
{
v15 = v14++ + v6;
result = DisplayClrPoint(v15, a2);
}
while ( v7 >= v14 );
}
else
{
v8 = abs32(v4);
v9 = v8 / v7;
if ( v8 / v7 )
{
if ( a4 < a2 )
{
v5 = a4;
v21 = a1 - a3;
v6 = a3;
}
v10 = 0;
v11 = 0;
do
{
v12 = v11++ + v5;
result = DisplayClrPoint((unsigned __int16)(v10 / v8) + v6, v12);
v10 += v21;
}
while ( v8 >= v11 );
}
else
{
if ( a3 < a1 )
{
v6 = a3;
v5 = a4;
v4 = a2 - a4;
}
v18 = 0;
do
{
v19 = v18;
v20 = v9++ + v6;
v18 += v4;
result = DisplayClrPoint(v20, (unsigned __int16)(v19 / v7) + v5);
}
while ( v7 >= v9 );
}
}
}
return result;
}

original_code:
void DisplayClrLine (int x_start, int y_start, int x_end, int y_end)
{
 int x, y, temp, delta_x, delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplayClrPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplayClrPoint(x + x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for (y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplayClrPoint(x, y_start + y);
  }
 }
 else
 {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplayClrPoint(x_start + x, y);
  }
 }
}

canonical_original_code:
void DisplayClrLine(int x_start, int y_start, int x_end, int y_end)
{
 int x; int y; int temp; int delta_x; int delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplayClrPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplayClrPoint(x + x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for (y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplayClrPoint(x, y_start + y);
  }
 }
 else
 {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplayClrPoint(x_start + x, y);
  }
 }
}


decompiled_code:
__int64 __fastcall change_state(int *a1, int a2)
{
int v2; // eax

v2 = *a1;
if ( *a1 == 1 )
{
game_state_game(a1, 1LL);
}
else
{
if ( v2 != 2 )
{
if ( v2 )
goto LABEL_4;
game_state_menu(a1, 1LL);
*a1 = a2;
if ( a2 == 1 )
return game_state_game(a1, 0LL);
goto LABEL_7;
}
game_state_highscore(a1, 1LL);
}
*a1 = a2;
if ( a2 == 1 )
return game_state_game(a1, 0LL);
LABEL_7:
if ( a2 == 2 )
return game_state_highscore(a1, 0LL);
if ( a2 )
LABEL_4:
exit(-1);
return game_state_menu(a1, 0LL);
}

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

v2 = *a1;
if ( *a1 == 1 )
{
func2(a1, 1LL);
}
else
{
if ( v2 != 2 )
{
if ( v2 )
goto LABEL_4;
func1(a1, 1LL);
*a1 = a2;
if ( a2 == 1 )
return func2(a1, 0LL);
goto LABEL_7;
}
func3(a1, 1LL);
}
*a1 = a2;
if ( a2 == 1 )
return func2(a1, 0LL);
LABEL_7:
if ( a2 == 2 )
return func3(a1, 0LL);
if ( a2 )
LABEL_4:
exit(-1);
return func1(a1, 0LL);
}

original_code:
void change_state(Game *game, GameState new)
{
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventExit);
   break;
  case EStateGame:
   game_state_game(game, EEventExit);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventExit);
   break;
  default:
   exit(-1);
 }
 game->state = new;
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventEntry);
   break;
  case EStateGame:
   game_state_game(game, EEventEntry);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventEntry);
   break;
  default:
   exit(-1);
 }
}

canonical_original_code:
void change_state(struct Game *game, enum GameState new)
{
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventExit);
   break;
  case EStateGame:
   game_state_game(game, EEventExit);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventExit);
   break;
  default:
   exit(-1);
 }
 game->state = new;
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventEntry);
   break;
  case EStateGame:
   game_state_game(game, EEventEntry);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventEntry);
   break;
  default:
   exit(-1);
 }
}

variable_types: struct Game { enum GameState { EStateMenu=0, EStateGame=1, EStateHighScore=2 } state; struct Wall { float x; int y1; } wall; struct Heli { float x; float speed; } heli; struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } landscape; unsigned int menuitem; int scapeSize; unsigned int startTicks; unsigned int oldTime; unsigned int difficultyTimer; int keyState[4]; int keys[4]; int currentKey; unsigned int highscore[10]; } *

user_defined_types: struct Game { enum GameState state; struct Wall wall; struct Heli heli; struct Landscape landscape; unsigned int menuitem; int scapeSize; unsigned int startTicks; unsigned int oldTime; unsigned int difficultyTimer; int keyState[4]; int keys[4]; int currentKey; unsigned int highscore[10]; }


decompiled_code:
void __fastcall game_state_menu(int *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
__int64 v4; // rsi

if ( (_DWORD)a2 )
{
if ( (_DWORD)a2 == 3 )
{
v2 = a1[115];
if ( v2 == 97 )
{
MIODispWriteText(" ", (unsigned int)a1[102], 1LL);
v4 = (a1[102] & 1u) + 1;
a1[102] = v4;
MIODispWriteText(">", v4, 1LL);
}
else if ( v2 == 119 )
{
v3 = a1[102];
if ( v3 == 1 )
{
change_state(a1, 1);
}
else if ( v3 == 2 )
{
change_state(a1, 2);
}
}
}
}
else
{
DisplayClrArea(0LL, a2, 160LL, 80LL);
MIODispWriteText("> Start", 1LL, 1LL);
MIODispWriteText(" Highscore", 2LL, 1LL);
a1[102] = 1;
}
}

canonical_decompiled_code:
void __fastcall func1(int *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
__int64 v4; // rsi

if ( (_DWORD)a2 )
{
if ( (_DWORD)a2 == 3 )
{
v2 = a1[115];
if ( v2 == 97 )
{
MIODispWriteText(" ", (unsigned int)a1[102], 1LL);
v4 = (a1[102] & 1u) + 1;
a1[102] = v4;
MIODispWriteText(">", v4, 1LL);
}
else if ( v2 == 119 )
{
v3 = a1[102];
if ( v3 == 1 )
{
func0(a1, 1);
}
else if ( v3 == 2 )
{
func0(a1, 2);
}
}
}
}
else
{
DisplayClrArea(0LL, a2, 160LL, 80LL);
MIODispWriteText("> Start", 1LL, 1LL);
MIODispWriteText(" Highscore", 2LL, 1LL);
a1[102] = 1;
}
}

original_code:
void game_state_menu(Game *game, GameEvent event)
{
 static const unsigned nitem=2;
 if(event == EEventEntry) {
  DisplayClrArea (0, 0, 160, 80);
  MIODispWriteText("> Start",1,1);
  MIODispWriteText("  Highscore",2,1);
  game->menuitem=1;
  return;
 } else if(event == EEventExit) {
  return;
 } else if(event == EEventKeyDown) {
  switch(game->currentKey) {
   case SDLK_w:
    switch(game->menuitem) {
     case 1:
      change_state(game, EStateGame);
      break;
     case 2:
      change_state(game, EStateHighScore);
      break;
    }
    break;
   case SDLK_a:
    MIODispWriteText(" ",game->menuitem,1);
    game->menuitem = (game->menuitem%nitem)+1;
    MIODispWriteText(">",game->menuitem,1);
    break;
  }
 }
 else if(event == EEventRun) {
 }
}

canonical_original_code:
void game_state_menu(struct Game *game, enum GameEvent event)
{
 static unsigned int nitem = 2;
 if(event == EEventEntry) {
  DisplayClrArea (0, 0, 160, 80);
  MIODispWriteText("> Start",1,1);
  MIODispWriteText("  Highscore",2,1);
  game->menuitem=1;
  return;
 } else if(event == EEventExit) {
  return;
 } else if(event == EEventKeyDown) {
  switch(game->currentKey) {
   case SDLK_w:
    switch(game->menuitem) {
     case 1:
      change_state(game, EStateGame);
      break;
     case 2:
      change_state(game, EStateHighScore);
      break;
    }
    break;
   case SDLK_a:
    MIODispWriteText(" ",game->menuitem,1);
    game->menuitem = (game->menuitem%nitem)+1;
    MIODispWriteText(">",game->menuitem,1);
    break;
  }
 }
 else if(event == EEventRun) {
 }
}

variable_types: enum GameEvent { EEventEntry=0, EEventExit=1, EEventRun=2, EEventKeyDown=3, EEventKeyUp=4 }

variable_types:
nitem
unsigned int

user_defined_types: enum GameState { EStateMenu=0, EStateGame=1, EStateHighScore=2 }

user_defined_types: struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; }


decompiled_code:
void __fastcall game_state_game(__int64 a1, int a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
int v4; // eax
int v5; // ebx
unsigned int v6; // kr00_4
unsigned int v7; // er12
int v8; // eax
int v9; // eax
unsigned int v10; // ebx
__int64 v11; // rax
__int64 v12; // r12
unsigned int v13; // er12
unsigned int v14; // eax
__int64 v15; // rdx
unsigned int v16; // eax
__int64 v17; // rsi
char s[66]; // [rsp+6h] [rbp-42h] BYREF

if ( a2 )
{
if ( a2 == 1 )
{
v10 = ((unsigned int)SDL_GetTicks() - *(_DWORD *)(a1 + 416)) / 0x64;
printf("Score: %i\n", v10);
v11 = 0LL;
while ( 1 )
{
v12 = (unsigned int)v11;
if ( *(_DWORD *)(a1 + 4 * v11 + 464) < v10 )
break;
if ( ++v11 == 10 )
return;
}
if ( (_DWORD)v11 != 9 )
memmove(
(void *)(a1 - 4LL * (unsigned int)(8 - v11) + 500),
(const void *)(a1 - 4LL * (unsigned int)(8 - v11) + 496),
4LL * (unsigned int)(9 - v11));
*(_DWORD *)(a1 + 4 * v12 + 464) = v10;
}
else if ( a2 == 2 )
{
v5 = SDL_GetTicks();
v6 = v5 - *(_DWORD *)(a1 + 416);
v7 = v5 - *(_DWORD *)(a1 + 420);
*(_DWORD *)(a1 + 420) = v5;
sprintf(s, "%i", v6 / 0x64uLL);
MIODispWriteText(s, 9LL, 0LL);
if ( (unsigned int)(v5 - *(_DWORD *)(a1 + 424)) > 0x3E8 )
{
v8 = rangeYHight;
*(_DWORD *)(a1 + 424) = v5;
rangeYHight = v8 + 1;
if ( v8 + 1 > 40 )
{
*(_DWORD *)(a1 + 412) = 39;
}
else
{
v9 = *(_DWORD *)(a1 + 412) - 1;
if ( v9 > 9 )
*(_DWORD *)(a1 + 412) = v9;
else
*(_DWORD *)(a1 + 412) = 10;
}
}
heli_clear(a1 + 16);
if ( (unsigned int)DIORead(119LL) )
heli_update(a1 + 16, v7, 0.001);
else
heli_update(a1 + 16, v7, -0.001);
heli_draw(a1 + 16);
landscapeFlow(a1 + 28, *(unsigned int *)(a1 + 412));
wall_clear(a1 + 4);
wall_update(a1 + 4, v7);
if ( *(float *)(a1 + 4) <= 0.0 )
{
v13 = getYBottom(a1 + 28, 160LL);
v14 = getYRoof(a1 + 28, 160LL);
v15 = v14;
v16 = v14 - v13;
v17 = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8) + 1);
if ( (int)(v16 - 19) <= (int)v17 )
{
v17 = v16 - 20;
if ( (int)v17 <= 0 )
v17 = 1LL;
}
wall_init(a1 + 4, v17, v15, v13);
}
wall_draw(a1 + 4);
if ( (unsigned int)heli_check_collision(
a1 + 16,
*(float *)(a1 + 4),
(float)*(int *)(a1 + 8),
*(float *)(a1 + 4),
(float)*(int *)(a1 + 12)) )
change_state((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) + 5.0)) )
change_state((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) - 5.0)) )
change_state((int *)a1, 2);
}
}
else
{
puts("game entry");
rangeYHight = 1;
DisplayClrArea(0LL, 0LL, 160LL, 80LL);
initLandscape(a1 + 28, 70LL);
heli_init(a1 + 16);
v2 = getYBottom(a1 + 28, 159LL);
v3 = getYRoof(a1 + 28, 159LL);
wall_init(a1 + 4, 10LL, v3, v2);
*(_DWORD *)(a1 + 412) = 70;
v4 = SDL_GetTicks();
*(_DWORD *)(a1 + 416) = v4;
*(_DWORD *)(a1 + 420) = v4;
*(_DWORD *)(a1 + 424) = v4;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
int v4; // eax
int v5; // ebx
unsigned int v6; // kr00_4
unsigned int v7; // er12
int v8; // eax
int v9; // eax
unsigned int v10; // ebx
__int64 v11; // rax
__int64 v12; // r12
unsigned int v13; // er12
unsigned int v14; // eax
__int64 v15; // rdx
unsigned int v16; // eax
__int64 v17; // rsi
char s[66]; // [rsp+6h] [rbp-42h] BYREF

if ( a2 )
{
if ( a2 == 1 )
{
v10 = ((unsigned int)SDL_GetTicks() - *(_DWORD *)(a1 + 416)) / 0x64;
printf("Score: %i\n", v10);
v11 = 0LL;
while ( 1 )
{
v12 = (unsigned int)v11;
if ( *(_DWORD *)(a1 + 4 * v11 + 464) < v10 )
break;
if ( ++v11 == 10 )
return;
}
if ( (_DWORD)v11 != 9 )
memmove(
(void *)(a1 - 4LL * (unsigned int)(8 - v11) + 500),
(const void *)(a1 - 4LL * (unsigned int)(8 - v11) + 496),
4LL * (unsigned int)(9 - v11));
*(_DWORD *)(a1 + 4 * v12 + 464) = v10;
}
else if ( a2 == 2 )
{
v5 = SDL_GetTicks();
v6 = v5 - *(_DWORD *)(a1 + 416);
v7 = v5 - *(_DWORD *)(a1 + 420);
*(_DWORD *)(a1 + 420) = v5;
sprintf(s, "%i", v6 / 0x64uLL);
MIODispWriteText(s, 9LL, 0LL);
if ( (unsigned int)(v5 - *(_DWORD *)(a1 + 424)) > 0x3E8 )
{
v8 = rangeYHight;
*(_DWORD *)(a1 + 424) = v5;
rangeYHight = v8 + 1;
if ( v8 + 1 > 40 )
{
*(_DWORD *)(a1 + 412) = 39;
}
else
{
v9 = *(_DWORD *)(a1 + 412) - 1;
if ( v9 > 9 )
*(_DWORD *)(a1 + 412) = v9;
else
*(_DWORD *)(a1 + 412) = 10;
}
}
heli_clear(a1 + 16);
if ( (unsigned int)DIORead(119LL) )
heli_update(a1 + 16, v7, 0.001);
else
heli_update(a1 + 16, v7, -0.001);
heli_draw(a1 + 16);
landscapeFlow(a1 + 28, *(unsigned int *)(a1 + 412));
wall_clear(a1 + 4);
wall_update(a1 + 4, v7);
if ( *(float *)(a1 + 4) <= 0.0 )
{
v13 = getYBottom(a1 + 28, 160LL);
v14 = getYRoof(a1 + 28, 160LL);
v15 = v14;
v16 = v14 - v13;
v17 = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8) + 1);
if ( (int)(v16 - 19) <= (int)v17 )
{
v17 = v16 - 20;
if ( (int)v17 <= 0 )
v17 = 1LL;
}
wall_init(a1 + 4, v17, v15, v13);
}
wall_draw(a1 + 4);
if ( (unsigned int)heli_check_collision(
a1 + 16,
*(float *)(a1 + 4),
(float)*(int *)(a1 + 8),
*(float *)(a1 + 4),
(float)*(int *)(a1 + 12)) )
func0((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) + 5.0)) )
func0((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) - 5.0)) )
func0((int *)a1, 2);
}
}
else
{
puts("game entry");
rangeYHight = 1;
DisplayClrArea(0LL, 0LL, 160LL, 80LL);
initLandscape(a1 + 28, 70LL);
heli_init(a1 + 16);
v2 = getYBottom(a1 + 28, 159LL);
v3 = getYRoof(a1 + 28, 159LL);
wall_init(a1 + 4, 10LL, v3, v2);
*(_DWORD *)(a1 + 412) = 70;
v4 = SDL_GetTicks();
*(_DWORD *)(a1 + 416) = v4;
*(_DWORD *)(a1 + 420) = v4;
*(_DWORD *)(a1 + 424) = v4;
}
}

original_code:
void game_state_game(Game *game, GameEvent event)
{
 if(event == EEventEntry) {
  printf("game entry\n");
  rangeYHight = 1;
  DisplayClrArea (0, 0, 160, 80);
  initLandscape(&game->landscape, 70);
  heli_init(&game->heli);
  wall_init(&game->wall, 10, getYRoof(&game->landscape, 159), getYBottom(&game->landscape, 159) );
  game->scapeSize=70;
  game->startTicks = SDL_GetTicks();
  game->oldTime = game->startTicks;
  game->difficultyTimer = game->startTicks;
 } else if(event == EEventExit) {
  Uint32 time = SDL_GetTicks();
  Uint32 score = (time-game->startTicks)/100;
  printf("Score: %i\n", score);
  for(unsigned i=0; i<10; ++i) {
   if(score > game->highscore[i]) {
    for(unsigned j=10 -1; j>i; --j) {
     game->highscore[j] = game->highscore[j-1];
    }
    game->highscore[i] = score;
    break;
   }
  }
 } else if(event == EEventRun) {
  Uint32 time = SDL_GetTicks();
  Uint32 diffTime = time-game->oldTime;
  game->oldTime=time;
  char buf[10];
  sprintf(buf, "%i", (time-game->startTicks)/100);
  MIODispWriteText(buf, 9, 0);
  if((time - game->difficultyTimer) >1000) {
   game->difficultyTimer = time;
   rangeYHight++;
   if(rangeYHight > 40 ) game->scapeSize = 40;
   game->scapeSize--;
   if(game->scapeSize < 10 ) game->scapeSize = 10;
  }
  heli_clear(&game->heli);
  if(DIORead(SDLK_w)) {
   heli_update(&game->heli, 0.001, diffTime);
  }
  else {
   heli_update(&game->heli, -0.001, diffTime);
  }
  heli_draw(&game->heli);
  landscapeFlow(&game->landscape, game->scapeSize);
  wall_clear(&game->wall);
  wall_update(&game->wall, diffTime);
  if(game->wall.x <=0 ) {
   int length;
   int ymin, ymax;
   ymin = getYBottom(&game->landscape, 160);
   ymax = getYRoof(&game->landscape, 160);
   length = game->wall.y2-game->wall.y1+1;
   if(length>(ymax-ymin-20) ) {
    length = ymax-ymin-20;
    if(length<1) length = 1;
   }
   wall_init(&game->wall, length, ymax, ymin );
  }
  wall_draw(&game->wall);
  if(heli_check_collision(&game->heli, game->wall.x, game->wall.y1, game->wall.x, game->wall.y2)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y+heliRadius)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y-heliRadius)) {
   change_state(game, EStateHighScore);
  }
 }
}

canonical_original_code:
void game_state_game(struct Game *game, enum GameEvent event)
{
 if(event == EEventEntry) {
  printf("game entry\n");
  rangeYHight = 1;
  DisplayClrArea (0, 0, 160, 80);
  initLandscape(&game->landscape, 70);
  heli_init(&game->heli);
  wall_init(&game->wall, 10, getYRoof(&game->landscape, 159), getYBottom(&game->landscape, 159) );
  game->scapeSize=70;
  game->startTicks = SDL_GetTicks();
  game->oldTime = game->startTicks;
  game->difficultyTimer = game->startTicks;
 } else if(event == EEventExit) {
  unsigned int time = SDL_GetTicks();
  unsigned int score = (time-game->startTicks)/100;
  printf("Score: %i\n", score);
  for(unsigned int i = 0; i<10; ++i) {
   if(score > game->highscore[i]) {
    for(unsigned int j = 10 -1; j>i; --j) {
     game->highscore[j] = game->highscore[j-1];
    }
    game->highscore[i] = score;
    break;
   }
  }
 } else if(event == EEventRun) {
  unsigned int time = SDL_GetTicks();
  unsigned int diffTime = time-game->oldTime;
  game->oldTime=time;
  char buf[10];
  sprintf(buf, "%i", (time-game->startTicks)/100);
  MIODispWriteText(buf, 9, 0);
  if((time - game->difficultyTimer) >1000) {
   game->difficultyTimer = time;
   rangeYHight++;
   if(rangeYHight > 40 ) game->scapeSize = 40;
   game->scapeSize--;
   if(game->scapeSize < 10 ) game->scapeSize = 10;
  }
  heli_clear(&game->heli);
  if(DIORead(SDLK_w)) {
   heli_update(&game->heli, 0.001, diffTime);
  }
  else {
   heli_update(&game->heli, -0.001, diffTime);
  }
  heli_draw(&game->heli);
  landscapeFlow(&game->landscape, game->scapeSize);
  wall_clear(&game->wall);
  wall_update(&game->wall, diffTime);
  if(game->wall.x <=0 ) {
   int length;
   int ymin; int ymax;
   ymin = getYBottom(&game->landscape, 160);
   ymax = getYRoof(&game->landscape, 160);
   length = game->wall.y2-game->wall.y1+1;
   if(length>(ymax-ymin-20) ) {
    length = ymax-ymin-20;
    if(length<1) length = 1;
   }
   wall_init(&game->wall, length, ymax, ymin );
  }
  wall_draw(&game->wall);
  if(heli_check_collision(&game->heli, game->wall.x, game->wall.y1, game->wall.x, game->wall.y2)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y+heliRadius)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y-heliRadius)) {
   change_state(game, EStateHighScore);
  }
 }
}

variable_types:
time
unsigned int

variable_types:
score
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
diffTime
unsigned int

variable_types:
buf
char [10]

variable_types: length int

variable_types: ymin int

variable_types: ymax int

user_defined_types: enum GameEvent { EEventEntry=0, EEventExit=1, EEventRun=2, EEventKeyDown=3, EEventKeyUp=4 }


decompiled_code:
__int64 __fastcall game_state_highscore(int *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

if ( a2 )
{
if ( a2 == 3 && a1[115] == 119 )
result = change_state(a1, 0);
}
else
{
for ( i = 0LL; i != 10; ++i )
{
sprintf(s, "%2u. %4i", (unsigned int)(i + 1), (unsigned int)a1[i + 116]);
result = MIODispWriteText(s, (unsigned int)i, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

if ( a2 )
{
if ( a2 == 3 && a1[115] == 119 )
result = func0(a1, 0);
}
else
{
for ( i = 0LL; i != 10; ++i )
{
sprintf(s, "%2u. %4i", (unsigned int)(i + 1), (unsigned int)a1[i + 116]);
result = MIODispWriteText(s, (unsigned int)i, 0LL);
}
}
return result;
}

original_code:
void game_state_highscore(Game *game, GameEvent event)
{
 if(event == EEventEntry) {
  char buf[10];
  for(unsigned i=0; i<10; ++i) {
   sprintf(buf, "%2u. %4i", i+1, game->highscore[i]);
   MIODispWriteText(buf, i, 0);
  }
 } else if(event == EEventExit) {
 } else if(event == EEventKeyDown) {
  if(game->currentKey == SDLK_w) {
   change_state(game, EStateMenu);
  }
 }
 else if(event == EEventRun) {
 }
}

canonical_original_code:
void game_state_highscore(struct Game *game, enum GameEvent event)
{
 if(event == EEventEntry) {
  char buf[10];
  for(unsigned int i = 0; i<10; ++i) {
   sprintf(buf, "%2u. %4i", i+1, game->highscore[i]);
   MIODispWriteText(buf, i, 0);
  }
 } else if(event == EEventExit) {
 } else if(event == EEventKeyDown) {
  if(game->currentKey == SDLK_w) {
   change_state(game, EStateMenu);
  }
 }
 else if(event == EEventRun) {
 }
}


original_code:
Game* game_init()
{
 Game* game = malloc(sizeof(Game));
 for(unsigned i=0; i< 10; ++i) {
  game->highscore[i] = 0;
 }
 for(unsigned i=0; i<4; ++i) {
  game->keyState[i] = 0;
 }
 game->keys[0] = SDLK_w;
 game->keys[1] = SDLK_a;
 game->keys[2] = SDLK_d;
 game->keys[3] = SDLK_s;
 game->menuitem = 0;
 game->scapeSize = 0;
 game->startTicks = 0;
 game->oldTime = 0;
 game->difficultyTimer = 0;
 game->state = EStateMenu;
 game_state_menu(game, EEventEntry);
 return game;
}

canonical_original_code:
struct Game *game_init()
{
 struct Game *game = malloc(sizeof(Game));
 for(unsigned int i = 0; i< 10; ++i) {
  game->highscore[i] = 0;
 }
 for(unsigned int i = 0; i<4; ++i) {
  game->keyState[i] = 0;
 }
 game->keys[0] = SDLK_w;
 game->keys[1] = SDLK_a;
 game->keys[2] = SDLK_d;
 game->keys[3] = SDLK_s;
 game->menuitem = 0;
 game->scapeSize = 0;
 game->startTicks = 0;
 game->oldTime = 0;
 game->difficultyTimer = 0;
 game->state = EStateMenu;
 game_state_menu(game, EEventEntry);
 return game;
}

return_type: struct Game { enum GameState { EStateMenu=0, EStateGame=1, EStateHighScore=2 } state; struct Wall { float x; int y1; } wall; struct Heli { float x; float speed; } heli; struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } landscape; unsigned int menuitem; int scapeSize; unsigned int startTicks; unsigned int oldTime; unsigned int difficultyTimer; int keyState[4]; int keys[4]; int currentKey; unsigned int highscore[10]; } *


decompiled_code:
void __fastcall game_run(int *a1)
{
__int64 v1; // rbx
int v2; // eax
__int64 v3; // rsi
int v4; // eax

v1 = 0LL;
DelayMs(10LL);
while ( 1 )
{
v2 = DIORead((unsigned int)a1[v1 + 111]);
if ( v2 )
break;
if ( a1[v1 + 107] )
{
v3 = 4LL;
a1[115] = a1[(unsigned int)v1 + 111];
a1[(unsigned int)v1 + 107] = 0;
goto LABEL_6;
}
LABEL_4:
if ( ++v1 == 4 )
{
v3 = 2LL;
goto LABEL_6;
}
}
if ( a1[v1 + 107] )
goto LABEL_4;
v3 = 3LL;
a1[115] = a1[(unsigned int)v1 + 111];
a1[(unsigned int)v1 + 107] = v2;
LABEL_6:
v4 = *a1;
if ( *a1 == 1 )
{
game_state_game((__int64)a1, v3);
}
else if ( v4 == 2 )
{
game_state_highscore(a1, v3);
}
else
{
if ( v4 )
exit(-1);
game_state_menu(a1, v3);
}
}

canonical_decompiled_code:
void __fastcall func5(int *a1)
{
__int64 v1; // rbx
int v2; // eax
__int64 v3; // rsi
int v4; // eax

v1 = 0LL;
DelayMs(10LL);
while ( 1 )
{
v2 = DIORead((unsigned int)a1[v1 + 111]);
if ( v2 )
break;
if ( a1[v1 + 107] )
{
v3 = 4LL;
a1[115] = a1[(unsigned int)v1 + 111];
a1[(unsigned int)v1 + 107] = 0;
goto LABEL_6;
}
LABEL_4:
if ( ++v1 == 4 )
{
v3 = 2LL;
goto LABEL_6;
}
}
if ( a1[v1 + 107] )
goto LABEL_4;
v3 = 3LL;
a1[115] = a1[(unsigned int)v1 + 111];
a1[(unsigned int)v1 + 107] = v2;
LABEL_6:
v4 = *a1;
if ( *a1 == 1 )
{
func2((__int64)a1, v3);
}
else if ( v4 == 2 )
{
func3(a1, v3);
}
else
{
if ( v4 )
exit(-1);
func1(a1, v3);
}
}

original_code:
void game_run(Game *game)
{
 GameEvent event = EEventRun;
 DelayMs(10);
 for(unsigned i=0; i<4; ++i) {
  int state = DIORead(game->keys[i]);
  if(state && game->keyState[i]==0) {
   event = EEventKeyDown;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  } else if(state == 0 && game->keyState[i]) {
   event = EEventKeyUp;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  }
 }
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, event);
   break;
  case EStateGame:
   game_state_game(game, event);
   break;
  case EStateHighScore:
   game_state_highscore(game, event);
   break;
  default:
   exit(-1);
 }
}

canonical_original_code:
void game_run(struct Game *game)
{
 enum GameEvent event = EEventRun;
 DelayMs(10);
 for(unsigned int i = 0; i<4; ++i) {
  int state = DIORead(game->keys[i]);
  if(state && game->keyState[i]==0) {
   event = EEventKeyDown;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  } else if(state == 0 && game->keyState[i]) {
   event = EEventKeyUp;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  }
 }
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, event);
   break;
  case EStateGame:
   game_state_game(game, event);
   break;
  case EStateHighScore:
   game_state_highscore(game, event);
   break;
  default:
   exit(-1);
 }
}

variable_types: state int


original_code:
void wall_init(Wall *wall, int length, int ymax, int ymin)
{
 printf("%i, %i, %i ->", length, ymax, ymin);
 wall->x=160;
 wall->y1=ymin+(rand()%(ymax-ymin-length));
 wall->y2=wall->y1+length;
 printf("%i, %i\n", wall->y1, wall->y2);
}

canonical_original_code:
void wall_init(struct Wall *wall, int length, int ymax, int ymin)
{
 printf("%i, %i, %i ->", length, ymax, ymin);
 wall->x=160;
 wall->y1=ymin+(rand()%(ymax-ymin-length));
 wall->y2=wall->y1+length;
 printf("%i, %i\n", wall->y1, wall->y2);
}

variable_types:
wall
struct Wall { float x; int y1; } *


decompiled_code:
void __fastcall wall_update(float *a1)
{
*a1 = *a1 - 1.0;
}

canonical_decompiled_code:
void __fastcall func1(float *a1)
{
*a1 = *a1 - 1.0;
}

original_code:
void wall_update(Wall *wall, int dtime)
{
 wall->x-=1;
}

canonical_original_code:
void wall_update(struct Wall *wall, int dtime)
{
 wall->x-=1;
}

variable_types: dtime int


decompiled_code:
__int64 __fastcall wall_draw(__int64 a1)
{
return DisplayDrawLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return DisplayDrawLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

original_code:
void wall_draw(Wall *wall)
{
 DisplayDrawLine(wall->x,wall->y1,wall->x,wall->y2);
}

canonical_original_code:
void wall_draw(struct Wall *wall)
{
 DisplayDrawLine(wall->x,wall->y1,wall->x,wall->y2);
}


decompiled_code:
__int64 __fastcall wall_clear(__int64 a1)
{
return DisplayClrLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return DisplayClrLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

original_code:
void wall_clear(Wall *wall)
{
 DisplayClrLine(wall->x,wall->y1,wall->x,wall->y2);
}

canonical_original_code:
void wall_clear(struct Wall *wall)
{
 DisplayClrLine(wall->x,wall->y1,wall->x,wall->y2);
}


initLandscape

original_code:
void initLandscape(Landscape *lndscp, int deltaY)
{
  int j;
  lndscp->nrOfPnts = 0;
  lndscp->xPnts[0] = 0;
  lndscp->yBottom[0] = rand()%rangeYHight;
  lndscp->yRoof[0] = lndscp->yBottom[0] + deltaY + rand()%rangeAdditionalYDistance;
  lndscp->yBorderLeftBottom = lndscp->yBottom[0];
  lndscp->yBorderLeftRoof = lndscp->yRoof[0];
  do
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                      + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                      + deltaY + rand() % rangeAdditionalYDistance;
  } while (lndscp->xPnts[lndscp->nrOfPnts] <= xMax);
  for (j = 1; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j-1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}

canonical_original_code:
void initLandscape(struct Landscape *lndscp, int deltaY)
{
  int j;
  lndscp->nrOfPnts = 0;
  lndscp->xPnts[0] = 0;
  lndscp->yBottom[0] = rand()%rangeYHight;
  lndscp->yRoof[0] = lndscp->yBottom[0] + deltaY + rand()%rangeAdditionalYDistance;
  lndscp->yBorderLeftBottom = lndscp->yBottom[0];
  lndscp->yBorderLeftRoof = lndscp->yRoof[0];
  do
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                      + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                      + deltaY + rand() % rangeAdditionalYDistance;
  } while (lndscp->xPnts[lndscp->nrOfPnts] <= xMax);
  for (j = 1; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j-1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}

variable_types: struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } *

variable_types: deltaY int

variable_types: j int


landscapeFlow

original_code:
void landscapeFlow(Landscape *lndscp, int deltaY)
{
  int j;
  DisplayClrLine(0, lndscp->yBorderLeftBottom,
                 lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayClrLine(0, lndscp->yBorderLeftRoof,
                 lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                   lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                   lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightBottom);
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightRoof);
  for (j = 0; j <= lndscp->nrOfPnts; j++)
  {
    lndscp->xPnts[j]--;
  }
  if (lndscp->xPnts[lndscp->nrOfPnts] < 160)
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                              + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                              + deltaY + rand() % rangeAdditionalYDistance;
  }
  if (lndscp->xPnts[1] < 0)
  {
    for(j = 0; j < lndscp->nrOfPnts ; j++)
    {
      lndscp->xPnts[j] = lndscp->xPnts[j + 1];
      lndscp->yBottom[j] = lndscp->yBottom[j + 1];
      lndscp->yRoof[j] = lndscp->yRoof[j + 1];
    }
    lndscp->nrOfPnts--;
  }
  lndscp->yBorderLeftBottom = lndscp->yBottom[0]
    + ((lndscp->yBottom[1] - lndscp->yBottom[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  lndscp->yBorderLeftRoof = lndscp->yRoof[0]
    + ((lndscp->yRoof[1]-lndscp->yRoof[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  DisplayDrawLine(0, lndscp->yBorderLeftBottom,
                  lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayDrawLine(0, lndscp->yBorderLeftRoof,
                  lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}

canonical_original_code:
void landscapeFlow(struct Landscape *lndscp, int deltaY)
{
  int j;
  DisplayClrLine(0, lndscp->yBorderLeftBottom,
                 lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayClrLine(0, lndscp->yBorderLeftRoof,
                 lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                   lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                   lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightBottom);
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightRoof);
  for (j = 0; j <= lndscp->nrOfPnts; j++)
  {
    lndscp->xPnts[j]--;
  }
  if (lndscp->xPnts[lndscp->nrOfPnts] < 160)
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                              + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                              + deltaY + rand() % rangeAdditionalYDistance;
  }
  if (lndscp->xPnts[1] < 0)
  {
    for(j = 0; j < lndscp->nrOfPnts ; j++)
    {
      lndscp->xPnts[j] = lndscp->xPnts[j + 1];
      lndscp->yBottom[j] = lndscp->yBottom[j + 1];
      lndscp->yRoof[j] = lndscp->yRoof[j + 1];
    }
    lndscp->nrOfPnts--;
  }
  lndscp->yBorderLeftBottom = lndscp->yBottom[0]
    + ((lndscp->yBottom[1] - lndscp->yBottom[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  lndscp->yBorderLeftRoof = lndscp->yRoof[0]
    + ((lndscp->yRoof[1]-lndscp->yRoof[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  DisplayDrawLine(0, lndscp->yBorderLeftBottom,
                  lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayDrawLine(0, lndscp->yBorderLeftRoof,
                  lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}