decompiled_code:
__int64 __fastcall turn_attr_on(unsigned int a1, int a2)
{
return a2 | a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2)
{
return a2 | a1;
}

original_code:
int turn_attr_on(int var, int attr)
{
  return var | attr;
}


repo: gcali/minesweeper

original_code:
int string_append(char **string, int *dim, char c) {
  if (*string == ((void *)0)) {
    *string = malloc(sizeof(char) * 50);
    *dim = 50;
    (*string)[0] = c;
    (*string)[1] = '\0';
    return 1;
  }
  if (strlen(*string) + 2 > *dim) {
   char *temp_string;
   temp_string = realloc(*string, (*dim) + 50);
   *string = temp_string;
   *dim = *dim + 50;
  }
  {
    int i;
    for (i = 0; (*string)[i] != '\0'; i++)
      ;
    (*string)[i] = c;
    (*string)[i+1] = '\0';
  }
  return 1;
}

variable_types:
string
char **

variable_types:
dim
int *

variable_types: c char

variable_types: i int

return_type: int


original_code:
int string_to_num(int *num, const char *string) {
 int i;
 int fact;
 *num = 0;
  fact = 1;
 for (i = 0; string[i] != '\0'; i++) {
  if (i == 0 && string[i] == '-')
   fact *= -1;
  else if (!((string[i]) >= '0' && (string[i]) <= '9')) {
   return 1;
  }
  else {
   *num *= 10;
   *num += string[i] - '0';
  }
 }
  *num *= fact;
 return 0;
}

canonical_original_code:
int string_to_num(int *num, char *string) {
 int i;
 int fact;
 *num = 0;
  fact = 1;
 for (i = 0; string[i] != '\0'; i++) {
  if (i == 0 && string[i] == '-')
   fact *= -1;
  else if (!((string[i]) >= '0' && (string[i]) <= '9')) {
   return 1;
  }
  else {
   *num *= 10;
   *num += string[i] - '0';
  }
 }
  *num *= fact;
 return 0;
}

variable_types:
num
int *

variable_types:
string
char *

variable_types: fact int


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

result = 0LL;
if ( a2 >= 0 )
{
if ( a2 <= 0 )
{
result = 1LL;
}
else
{
LODWORD(result) = 1;
do
{
result = (unsigned int)(a1 * result);
--a2;
}
while ( a2 );
}
}
return result;
}

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

result = 0LL;
if ( a2 >= 0 )
{
if ( a2 <= 0 )
{
result = 1LL;
}
else
{
LODWORD(result) = 1;
do
{
result = (unsigned int)(a1 * result);
--a2;
}
while ( a2 );
}
}
return result;
}

original_code:
int pow_int(int base, int exp) {
  int res;
  res = 1;
  if (exp < 0)
    return 0;
  while (exp >= 1) {
    res *= base;
    exp--;
  }
  return res;
}

variable_types: base int

variable_types: exp int

variable_types: res int


decompiled_code:
__int64 __fastcall last_digit(unsigned int a1)
{
for ( ; a1 + 9 > 0x12; a1 = (int)a1 / 10 )
;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
for ( ; a1 + 9 > 0x12; a1 = (int)a1 / 10 )
;
return a1;
}

original_code:
int last_digit(int num) {
  while (num / 10 != 0)
    num /= 10;
  return num;
}

variable_types: num int


decompiled_code:
__int64 __fastcall number_of_digits(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
a1 /= 10;
++v1;
}
while ( a1 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
unsigned int v1; // edx

if ( !a1 )
return 0;
v1 = 0;
do
{
a1 /= 10;
++v1;
}
while ( a1 );
return v1;
}

original_code:
int number_of_digits(int num) {
  int digits;
  for (digits = 0; num != 0; digits++) {
    num /= 10;
  }
  return digits;
}

variable_types: digits int


decompiled_code:
__int64 __fastcall string_length(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int string_length(char *string) {
  int i;
  for (i = 0; string[i] != '\0'; i++)
    ;
  return i;
}


digit

decompiled_code:
__int64 __fastcall digit(int a1, int a2)
{
int v2; // ebx

v2 = a2 / (int)pow_int(10, a1);
return (unsigned int)(v2 % (int)pow_int(10, 2));
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
int v2; // ebx

v2 = a2 / (int)func8(10, a1);
return (unsigned int)(v2 % (int)func8(10, 2));
}

original_code:
int digit(int digit_number, int num) {
  num /= pow_int(10, digit_number);
  num %= pow_int(10, 2);
  return num;
}


chomp

decompiled_code:
__int64 __fastcall chomp(const char *a1)
{
a1[strlen(a1) - 1] = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(const char *a1)
{
a1[strlen(a1) - 1] = 0;
return 0LL;
}

original_code:
int chomp (char *string) {
  string[strlen(string) - 1] = '\0';
  return 0;
}

canonical_original_code:
int chomp(char *string) {
  string[strlen(string) - 1] = '\0';
  return 0;
}


decompiled_code:
__int64 __fastcall is_string_a_number(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0LL;
do
{
if ( (unsigned __int8)(v1 - 48) > 9u && (v1 != 45 || (_DWORD)v2) )
return 0LL;
v1 = a1[++v2];
}
while ( v1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0LL;
do
{
if ( (unsigned __int8)(v1 - 48) > 9u && (v1 != 45 || (_DWORD)v2) )
return 0LL;
v1 = a1[++v2];
}
while ( v1 );
return 1LL;
}

original_code:
int is_string_a_number(char *string) {
  int i;
  for (i = 0; string[i] != '\0'; i++) {
    if (!((string[i]) >= '0' && (string[i]) <= '9'))
      if (i != 0 || string[i] != '-')
        return 0;
  }
  return 1;
}


decompiled_code:
__int64 __fastcall highscore_std_cmp(__int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v4; // esi
__int64 result; // rax

if ( a1 < a3 )
return 0xFFFFFFFFLL;
v4 = a2 - a4;
result = 1LL;
if ( a1 <= a3 )
result = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3, int a4)
{
unsigned int v4; // esi
__int64 result; // rax

if ( a1 < a3 )
return 0xFFFFFFFFLL;
v4 = a2 - a4;
result = 1LL;
if ( a1 <= a3 )
result = v4;
return result;
}

original_code:
static int highscore_std_cmp(Time a, Time b)
{
  if (a.sec < b.sec)
    return -1;
  else if (a.sec > b.sec)
    return 1;
  else
    return a.msec - b.msec;
}

canonical_original_code:
static int highscore_std_cmp(struct TimeStruct a, struct TimeStruct b)
{
  if (a.sec < b.sec)
    return -1;
  else if (a.sec > b.sec)
    return 1;
  else
    return a.msec - b.msec;
}

variable_types: struct TimeStruct { long sec; long msec; }

variable_types:
b
struct TimeStruct


decompiled_code:
__int64 highscore_close_down()
{
while ( score_list )
highscore_remove_first();
if ( scores_file )
{
free(scores_file);
scores_file = 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
while ( score_list )
func2();
if ( scores_file )
{
free(scores_file);
scores_file = 0LL;
}
return 0LL;
}

original_code:
int highscore_close_down()
{
  while (score_list != ((void *)0))
    highscore_remove_first();
  if (scores_file != ((void *)0))
  {
    free(scores_file);
    scores_file = ((void *)0);
  }
  return (0);
}


decompiled_code:
__int64 __fastcall highscore_destroy(__int64 a1, int a2)
{
void **v2; // rbx

if ( !a2 )
return 0LL;
v2 = (void **)(a1 + 24);
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
v2 += 4;
}
while ( v2 != (void **)(a1 + 32LL * (unsigned int)(a2 - 1) + 56) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
void **v2; // rbx

if ( !a2 )
return 0LL;
v2 = (void **)(a1 + 24);
do
{
if ( *v2 )
{
free(*v2);
*v2 = 0LL;
}
v2 += 4;
}
while ( v2 != (void **)(a1 + 32LL * (unsigned int)(a2 - 1) + 56) );
return 0LL;
}

original_code:
int highscore_destroy(Score array[], unsigned int nmemb)
{
  int i;
  for (i = 0; i < nmemb; i++)
    if (array[i].name != ((void *)0))
    {
      free(array[i].name);
      array[i].name = ((void *)0);
    }
  return (0);
}

canonical_original_code:
int highscore_destroy(struct ScoreStruct array[], unsigned int nmemb)
{
  int i;
  for (i = 0; i < nmemb; i++)
    if (array[i].name != ((void *)0))
    {
      free(array[i].name);
      array[i].name = ((void *)0);
    }
  return (0);
}

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } []

variable_types:
nmemb
unsigned int

user_defined_types: struct ScoreStruct { int id; struct TimeStruct time; char *name; }


decompiled_code:
__int64 __fastcall highscore_get_highscores(__int64 a1, unsigned int *a2, int a3)
{
char *v3; // rbx
unsigned int v5; // ebp
__int64 v6; // r12
size_t v7; // rax
char *v8; // rax

v3 = (char *)score_list;
if ( *a2 && score_list )
{
v5 = 0;
do
{
if ( *(_DWORD *)v3 == a3 )
{
v6 = a1 + 32LL * v5;
*(__m128i *)(v6 + 8) = _mm_loadu_si128((const __m128i *)(v3 + 8));
*(_DWORD *)v6 = *(_DWORD *)v3;
v7 = strlen(*((const char **)v3 + 3));
v8 = (char *)malloc(v7 + 1);
*(_QWORD *)(v6 + 24) = v8;
strcpy(v8, *((const char **)v3 + 3));
++v5;
}
v3 = (char *)*((_QWORD *)v3 + 4);
}
while ( *a2 > v5 && v3 );
}
else
{
v5 = 0;
}
*a2 = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int *a2, int a3)
{
char *v3; // rbx
unsigned int v5; // ebp
__int64 v6; // r12
size_t v7; // rax
char *v8; // rax

v3 = (char *)score_list;
if ( *a2 && score_list )
{
v5 = 0;
do
{
if ( *(_DWORD *)v3 == a3 )
{
v6 = a1 + 32LL * v5;
*(__m128i *)(v6 + 8) = _mm_loadu_si128((const __m128i *)(v3 + 8));
*(_DWORD *)v6 = *(_DWORD *)v3;
v7 = strlen(*((const char **)v3 + 3));
v8 = (char *)malloc(v7 + 1);
*(_QWORD *)(v6 + 24) = v8;
strcpy(v8, *((const char **)v3 + 3));
++v5;
}
v3 = (char *)*((_QWORD *)v3 + 4);
}
while ( *a2 > v5 && v3 );
}
else
{
v5 = 0;
}
*a2 = v5;
return 0LL;
}

original_code:
int highscore_get_highscores(Score *array, unsigned int *nmemb, int id)
{
  unsigned int i;
  List work_list;
  i = 0;
  work_list = score_list;
  while (i < *nmemb && work_list != ((void *)0))
  {
    if (work_list->score.id == id)
    {
      array[i].time = work_list->score.time;
      array[i].id = work_list->score.id;
      array[i].name = malloc(sizeof(char) * (strlen(work_list->score.name) + 1));
      strcpy(array[i].name, work_list->score.name);
      i++;
    }
    work_list = work_list->next;
  }
  if (i < *nmemb);
    *nmemb = i;
  return (0);
}

canonical_original_code:
int highscore_get_highscores(struct ScoreStruct *array, unsigned int *nmemb, int id)
{
  unsigned int i;
  struct NodeStruct *work_list;
  i = 0;
  work_list = score_list;
  while (i < *nmemb && work_list != ((void *)0))
  {
    if (work_list->score.id == id)
    {
      array[i].time = work_list->score.time;
      array[i].id = work_list->score.id;
      array[i].name = malloc(sizeof(char) * (strlen(work_list->score.name) + 1));
      strcpy(array[i].name, work_list->score.name);
      i++;
    }
    work_list = work_list->next;
  }
  if (i < *nmemb);
    *nmemb = i;
  return (0);
}

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } *

variable_types:
nmemb
unsigned int *

variable_types: id int

variable_types:
i
unsigned int

variable_types: struct NodeStruct { struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } score; struct NodeStruct *next; } *

user_defined_types: struct NodeStruct { struct ScoreStruct score; struct NodeStruct *next; }


decompiled_code:
__int64 __fastcall highscore_add_score_struct(int a1, int a2, int a3, int a4, int a5, int a6, int a7, __int128 a8, char *s)
{
char *v9; // r13
char *v10; // rbx
void **v11; // rbp
char *v12; // rbx
size_t v13; // rax
char *v14; // rax

v9 = s;
v10 = (char *)score_list;
v11 = &score_list;
if ( score_list )
{
do
{
if ( *(_DWORD *)v10 > a7 )
break;
if ( (int)highscore_std_cmp(*((_QWORD *)v10 + 1), *((_QWORD *)v10 + 2), a8, SDWORD2(a8)) > 0 )
break;
v11 = (void **)(v10 + 32);
v10 = (char *)*((_QWORD *)v10 + 4);
}
while ( v10 );
}
v12 = (char *)malloc(0x28uLL);
*(_DWORD *)v12 = a7;
*(__m128i *)(v12 + 8) = _mm_loadu_si128((const __m128i *)&a8);
v13 = strlen(v9);
v14 = (char *)malloc(v13 + 1);
*((_QWORD *)v12 + 3) = v14;
strcpy(v14, v9);
*((_QWORD *)v12 + 4) = *v11;
*v11 = v12;
return 0LL;
}

original_code:
int highscore_add_score_struct(Score score)
{
  List *work_list;
  List aux_list;
  work_list = &score_list;
  while (*work_list != ((void *)0) &&
         (*work_list)->score.id <= score.id &&
         highscore_std_cmp((*work_list)->score.time, score.time) <= 0)
    work_list = &((*work_list)->next);
  aux_list = malloc(sizeof(*aux_list));
  aux_list->score.id = score.id;
  aux_list->score.time = score.time;
  aux_list->score.name = malloc(sizeof(char) * (strlen(score.name) + 1));
  strcpy(aux_list->score.name, score.name);
  aux_list->next = *work_list;
  *work_list = aux_list;
  return (0);
}

canonical_original_code:
int highscore_add_score_struct(struct ScoreStruct score)
{
  struct NodeStruct **work_list;
  struct NodeStruct *aux_list;
  work_list = &score_list;
  while (*work_list != ((void *)0) &&
         (*work_list)->score.id <= score.id &&
         highscore_std_cmp((*work_list)->score.time, score.time) <= 0)
    work_list = &((*work_list)->next);
  aux_list = malloc(sizeof(*aux_list));
  aux_list->score.id = score.id;
  aux_list->score.time = score.time;
  aux_list->score.name = malloc(sizeof(char) * (strlen(score.name) + 1));
  strcpy(aux_list->score.name, score.name);
  aux_list->next = *work_list;
  *work_list = aux_list;
  return (0);
}

variable_types: struct NodeStruct { struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; } score; struct NodeStruct *next; } **


decompiled_code:
__int64 __fastcall highscore_add_score(int a1, __int64 a2, __int64 a3, char *a4, int a5, int a6)
{
__int128 v7; // [rsp-18h] [rbp-40h]

*((_QWORD *)&v7 + 1) = a3;
*(_QWORD *)&v7 = a2;
return highscore_add_score_struct(a1, a2, a3, (int)a4, a5, a6, a1, v7, a4);
}

original_code:
int highscore_add_score(int id, Time time, char *name)
{
  Score score;
  score.id = id;
  score.time = time;
  score.name = name;
  return highscore_add_score_struct(score);
}

canonical_original_code:
int highscore_add_score(int id, struct TimeStruct time, char *name)
{
  struct ScoreStruct score;
  score.id = id;
  score.time = time;
  score.name = name;
  return highscore_add_score_struct(score);
}

variable_types:
name
char *

variable_types: struct ScoreStruct { int id; struct TimeStruct { long sec; long msec; } time; char *name; }


decompiled_code:
__int64 highscore_init()
{
FILE *v0; // rdi

if ( !scores_file )
highscore_init_scores_file_string();
v0 = fopen(scores_file, "r");
highscore_stream = v0;
if ( v0 )
highscore_import_file(v0);
else
highscore_stream = fopen(scores_file, "w");
fclose(highscore_stream);
return 0LL;
}

canonical_decompiled_code:
__int64 func10()
{
FILE *v0; // rdi

if ( !scores_file )
func1();
v0 = fopen(scores_file, "r");
highscore_stream = v0;
if ( v0 )
func9(v0);
else
highscore_stream = fopen(scores_file, "w");
fclose(highscore_stream);
return 0LL;
}

original_code:
int highscore_init()
{
  if (scores_file == ((void *)0))
    highscore_init_scores_file_string();
  highscore_stream = fopen(scores_file, "r");
  if (highscore_stream == ((void *)0))
    highscore_stream = fopen(scores_file, "w");
  else
    highscore_import_file(highscore_stream);
  fclose(highscore_stream);
  return 0;
}


decompiled_code:
__int64 __fastcall highscore_is_score_top(_DWORD *a1, int a2, __int64 a3, int a4, int a5)
{
_QWORD *v7; // rbx
int v8; // er15
int v9; // ebp

v7 = score_list;
v8 = 0;
if ( score_list )
{
do
{
v9 = *(_DWORD *)v7;
if ( *(_DWORD *)v7 > a2 )
break;
if ( (int)highscore_std_cmp(v7[1], v7[2], a3, a4) > 0 )
break;
v8 += v9 == a2;
v7 = (_QWORD *)v7[4];
}
while ( v7 );
}
*a1 = a5 > v8;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1, int a2, __int64 a3, int a4, int a5)
{
_QWORD *v7; // rbx
int v8; // er15
int v9; // ebp

v7 = score_list;
v8 = 0;
if ( score_list )
{
do
{
v9 = *(_DWORD *)v7;
if ( *(_DWORD *)v7 > a2 )
break;
if ( (int)func0(v7[1], v7[2], a3, a4) > 0 )
break;
v8 += v9 == a2;
v7 = (_QWORD *)v7[4];
}
while ( v7 );
}
*a1 = a5 > v8;
return 0LL;
}

original_code:
int highscore_is_score_top(int *result, int id, Time time, int top)
{
  int i;
  List aux_list;
  aux_list = score_list;
  i = 0;
  while (aux_list != ((void *)0) &&
         aux_list->score.id <= id &&
         highscore_std_cmp(aux_list->score.time, time) <= 0)
  {
    if (aux_list->score.id == id)
      i++;
    aux_list = aux_list->next;
  }
  *result = i < top;
  return (0);
}

canonical_original_code:
int highscore_is_score_top(int *result, int id, struct TimeStruct time, int top)
{
  int i;
  struct NodeStruct *aux_list;
  aux_list = score_list;
  i = 0;
  while (aux_list != ((void *)0) &&
         aux_list->score.id <= id &&
         highscore_std_cmp(aux_list->score.time, time) <= 0)
  {
    if (aux_list->score.id == id)
      i++;
    aux_list = aux_list->next;
  }
  *result = i < top;
  return (0);
}

variable_types:
result
int *

variable_types: top int

variable_types: i int

user_defined_types: struct TimeStruct { long sec; long msec; }


decompiled_code:
__int64 highscore_print_debug()
{
_QWORD *v0; // rbx
int v1; // ebp

v0 = score_list;
if ( score_list )
{
v1 = 0;
do
{
printf("%02d) %ld.%ld | %s\n", (unsigned int)++v1, v0[1], v0[2], (const char *)v0[3]);
v0 = (_QWORD *)v0[4];
}
while ( v0 );
}
puts("---");
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
_QWORD *v0; // rbx
int v1; // ebp

v0 = score_list;
if ( score_list )
{
v1 = 0;
do
{
printf("%02d) %ld.%ld | %s\n", (unsigned int)++v1, v0[1], v0[2], (const char *)v0[3]);
v0 = (_QWORD *)v0[4];
}
while ( v0 );
}
puts("---");
return 0LL;
}

original_code:
int highscore_print_debug()
{
  List work_list;
  int i;
  work_list = score_list;
  i = 0;
  while (work_list != ((void *)0))
  {
    printf("%02d) %ld.%ld | %s\n", ++i,
                                 work_list->score.time.sec,
                                 work_list->score.time.msec,
                                 work_list->score.name);
    work_list = work_list->next;
  }
  printf("---\n");
  return (0);
}

canonical_original_code:
int highscore_print_debug()
{
  struct NodeStruct *work_list;
  int i;
  work_list = score_list;
  i = 0;
  while (work_list != ((void *)0))
  {
    printf("%02d) %ld.%ld | %s\n", ++i,
                                 work_list->score.time.sec,
                                 work_list->score.time.msec,
                                 work_list->score.name);
    work_list = work_list->next;
  }
  printf("---\n");
  return (0);
}


decompiled_code:
__int64 __fastcall highscore_get_id(_DWORD *a1, int a2, int a3)
{
*a1 = a3 + 100 * a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, int a2, int a3)
{
*a1 = a3 + 100 * a2;
return 0LL;
}

original_code:
int highscore_get_id(int *id, int row_dim, int col_dim)
{
  *id = row_dim * 100 + col_dim;
  return (0);
}

variable_types:
id
int *


decompiled_code:
__int64 timer_reset_time()
{
gettimeofday(&set_time, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
gettimeofday(&set_time, 0LL);
return 0LL;
}

original_code:
int timer_reset_time(void)
{
  gettimeofday(&set_time, ((void *)0));
  return (0);
}

canonical_original_code:
int timer_reset_time()
{
  gettimeofday(&set_time, ((void *)0));
  return (0);
}


decompiled_code:
__int64 __fastcall timer_get_elapsed_time(_QWORD *a1, __int64 *a2)
{
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v3, 0LL);
timer_distance(set_time.tv_sec, set_time.tv_usec, v3.tv_sec, v3.tv_usec, a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 *a2)
{
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v3, 0LL);
func0(set_time.tv_sec, set_time.tv_usec, v3.tv_sec, v3.tv_usec, a1, a2);
return 0LL;
}

original_code:
int timer_get_elapsed_time(long int *seconds, long int *milliseconds)
{
  struct timeval curr_time;
  gettimeofday(&curr_time, ((void *)0));
  timer_distance(set_time, curr_time, seconds, milliseconds);
  return (0);
}

canonical_original_code:
int timer_get_elapsed_time(long *seconds, long *milliseconds)
{
  struct timeval curr_time;
  gettimeofday(&curr_time, ((void *)0));
  timer_distance(set_time, curr_time, seconds, milliseconds);
  return (0);
}

variable_types:
seconds
long *

variable_types:
milliseconds
long *

variable_types: struct timeval { long tv_sec; long tv_usec; }


original_code:
int get_up_until(char **dest, int *sep_found,
                 char *string, int *offset,
                 char separator[], int dim)
{
  int i;
  int done;
  *dest = malloc(sizeof(char) * (strlen(string) + 1));
  string += *offset;
  i = 0;
  done = 0;
  while (string[i] != '\0' && !done)
  {
    int j = -1;
    while (++j < dim && !done)
      if (string[i] == separator[j])
      {
        done = 1;
        *sep_found = separator[j];
      }
    if (!done)
    {
      (*dest)[i] = string[i];
      i++;
    }
  }
  if (!done)
    *sep_found = '\0';
  (*dest)[i] = '\0';
  *offset += i+1;
  *dest = realloc(*dest, sizeof(char) * (strlen(*dest) + 1));
  return (0);
}

variable_types:
dest
char **

variable_types:
string
char *

variable_types:
offset
int *

variable_types:
separator
char []

variable_types: dim int

variable_types: done int

variable_types: j int


eval

repo: gchelfi/JeuxChiffres

decompiled_code:
__int64 __fastcall eval(int *a1, int *a2, char a3)
{
int v3; // edi
int v4; // ecx
__int64 result; // rax

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v4 = *a2;
if ( a3 == 45 )
{
result = (unsigned int)(v3 - v4);
if ( v3 <= v4 )
result = (unsigned int)(v4 - v3);
}
else if ( a3 > 45 )
{
if ( a3 == 47 )
{
if ( v3 <= v4 )
result = (unsigned int)(v4 / v3);
else
result = (unsigned int)(v3 / v4);
}
else
{
result = 0LL;
}
}
else if ( a3 == 42 )
{
result = (unsigned int)(v4 * v3);
}
else if ( a3 == 43 )
{
result = (unsigned int)(v3 + v4);
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1, int *a2, char a3)
{
int v3; // edi
int v4; // ecx
__int64 result; // rax

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
v3 = *a1;
v4 = *a2;
if ( a3 == 45 )
{
result = (unsigned int)(v3 - v4);
if ( v3 <= v4 )
result = (unsigned int)(v4 - v3);
}
else if ( a3 > 45 )
{
if ( a3 == 47 )
{
if ( v3 <= v4 )
result = (unsigned int)(v4 / v3);
else
result = (unsigned int)(v3 / v4);
}
else
{
result = 0LL;
}
}
else if ( a3 == 42 )
{
result = (unsigned int)(v4 * v3);
}
else if ( a3 == 43 )
{
result = (unsigned int)(v3 + v4);
}
else
{
result = 0LL;
}
return result;
}

original_code:
static int eval(Tree * P1, Tree * P2, char operator){
 int result = 0;
 int p1, p2;
 if (P1 && P2){
  p1 = P1->result;
  p2 = P2->result;
 }
  else {
    return -1;
  }
 switch (operator){
  case '+':
   result = p1 + p2;
   break;
  case '*':
   result = p1 * p2;
   break;
  case '-':
   if (p1 > p2) result = p1 - p2;
   else result = p2 - p1;
   break;
  case '/':
   if (p1 > p2) result = p1 / p2;
   else result = p2 / p1;
   break;
  default :
   break;
 }
 return result;
}

canonical_original_code:
static int eval(struct Node *P1, struct Node *P2, char operator){
 int result = 0;
 int p1; int p2;
 if (P1 && P2){
  p1 = P1->result;
  p2 = P2->result;
 }
  else {
    return -1;
  }
 switch (operator){
  case '+':
   result = p1 + p2;
   break;
  case '*':
   result = p1 * p2;
   break;
  case '-':
   if (p1 > p2) result = p1 - p2;
   else result = p2 - p1;
   break;
  case '/':
   if (p1 > p2) result = p1 / p2;
   else result = p2 / p1;
   break;
  default :
   break;
 }
 return result;
}

variable_types: struct Node { int result; char operator; struct Node *left; } *

variable_types: operator char

variable_types: result int


decompiled_code:
void __fastcall pretty_print(unsigned int *a1)
{
char v2; // al
_DWORD *v3; // rax
_DWORD *v4; // rdi

if ( a1 )
{
v2 = *((_BYTE *)a1 + 4);
if ( v2 == 111 )
{
printf("%d", *a1);
}
else if ( v2 == 42 )
{
pretty_print(*((_QWORD *)a1 + 1));
printf(" %c ", (unsigned int)*((char *)a1 + 4));
pretty_print(*((_QWORD *)a1 + 2));
}
else
{
putchar(40);
v3 = (_DWORD *)*((_QWORD *)a1 + 1);
v4 = (_DWORD *)*((_QWORD *)a1 + 2);
if ( *v3 <= *v4 )
{
pretty_print(v4);
printf(" %c ", (unsigned int)*((char *)a1 + 4));
pretty_print(*((_QWORD *)a1 + 1));
}
else
{
pretty_print(v3);
printf(" %c ", (unsigned int)*((char *)a1 + 4));
pretty_print(*((_QWORD *)a1 + 2));
}
putchar(41);
}
}
}

original_code:
static void pretty_print(Tree * tree){
 if(tree){
  if(tree->operator != 'o'){
   if(tree->operator == '*'){
    pretty_print(tree->left);
    printf(" %c ", tree->operator);
    pretty_print(tree->right);
   }
   else {
    printf("(");
    if(tree->left->result > tree->right->result) {
     pretty_print(tree->left);
     printf(" %c ", tree->operator);
     pretty_print(tree->right);
    }
    else {
     pretty_print(tree->right);
     printf(" %c ", tree->operator);
     pretty_print(tree->left);
    }
    printf(")");
   }
  }
  else {
   printf("%d", tree->result);
  }
 }
}

canonical_original_code:
static void pretty_print(struct Node *tree){
 if(tree){
  if(tree->operator != 'o'){
   if(tree->operator == '*'){
    pretty_print(tree->left);
    printf(" %c ", tree->operator);
    pretty_print(tree->right);
   }
   else {
    printf("(");
    if(tree->left->result > tree->right->result) {
     pretty_print(tree->left);
     printf(" %c ", tree->operator);
     pretty_print(tree->right);
    }
    else {
     pretty_print(tree->right);
     printf(" %c ", tree->operator);
     pretty_print(tree->left);
    }
    printf(")");
   }
  }
  else {
   printf("%d", tree->result);
  }
 }
}

return_type: void

user_defined_types: struct Node { int result; char operator; struct Node *left; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // rax
unsigned int v5; // ebx

closest = (__int64)new_tree(-1, 102);
v3 = time(0LL);
srand(v3);
if ( argc <= 1 )
{
printf("Usage: %s filename or %s N p [Int_list]\n", *argv, *argv);
}
else
{
if ( argc == 2 )
numbers_0 = (__int64)acquire_from_file(argv[1]);
else
numbers_0 = (__int64)acquire_from_command(argc, (__int64)argv);
v4 = transform(numbers_0);
cover((__int64)v4, p);
printf("Target: %d\n", (unsigned int)N);
printf("Available numbers: ");
if ( p )
{
v5 = 0;
do
printf("%d ", *(unsigned int *)(numbers_0 + 4LL * v5++));
while ( p > v5 );
}
puts("\nResult:");
pretty_print((unsigned int *)closest);
printf(" = %d\n", *(unsigned int *)closest);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
_QWORD *v4; // rax
unsigned int v5; // ebx

closest = (__int64)new_tree(-1, 102);
v3 = time(0LL);
srand(v3);
if ( argc <= 1 )
{
printf("Usage: %s filename or %s N p [Int_list]\n", *argv, *argv);
}
else
{
if ( argc == 2 )
numbers_0 = (__int64)func11(argv[1]);
else
numbers_0 = (__int64)acquire_from_command(argc, (__int64)argv);
v4 = transform(numbers_0);
func10((__int64)v4, p);
printf("Target: %d\n", (unsigned int)N);
printf("Available numbers: ");
if ( p )
{
v5 = 0;
do
printf("%d ", *(unsigned int *)(numbers_0 + 4LL * v5++));
while ( p > v5 );
}
puts("\nResult:");
func12((unsigned int *)closest);
printf(" = %d\n", *(unsigned int *)closest);
}
return 0;
}

original_code:
int main(int argc, char * argv[]){
 static int * numbers;
 unsigned int i;
 Tree ** Arbres;
 closest = new_tree(-1, 'f');
 srand(time(((void *)0)));
 if(argc < 2) {
  printf("Usage: %s filename or %s N p [Int_list]\n", argv[0], argv[0]);
  return 0;
 }
 if (argc == 2) {
  numbers = acquire_from_file(argv[1]);
 }
 if (argc > 2) {
  numbers = acquire_from_command(argc,argv);
 }
 Arbres = transform(numbers);
 cover(Arbres, p);
 printf("Target: %d\n", N);
 printf("Available numbers: ");
 for(i = 0; i < p; ++i){
  printf("%d ", numbers[i]);
  }
 printf("\nResult:\n");
 pretty_print(closest);
 printf(" = %d\n", closest->result);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
 static int *numbers;
 unsigned int i;
 struct Node **Arbres;
 closest = new_tree(-1, 'f');
 srand(time(((void *)0)));
 if(argc < 2) {
  printf("Usage: %s filename or %s N p [Int_list]\n", argv[0], argv[0]);
  return 0;
 }
 if (argc == 2) {
  numbers = acquire_from_file(argv[1]);
 }
 if (argc > 2) {
  numbers = acquire_from_command(argc,argv);
 }
 Arbres = transform(numbers);
 cover(Arbres, p);
 printf("Target: %d\n", N);
 printf("Available numbers: ");
 for(i = 0; i < p; ++i){
  printf("%d ", numbers[i]);
  }
 printf("\nResult:\n");
 pretty_print(closest);
 printf(" = %d\n", closest->result);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
numbers
int *

variable_types:
i
unsigned int

variable_types: struct Node { int result; char operator; struct Node *left; } **


repo: gchiesa/php-mfcobol

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4[120]; // [rsp+0h] [rbp-78h] BYREF

if ( argc != 2 )
{
printf("Usage: %s <LOGFILE>\n", *argv);
exit(1);
}
strcpy(v4, argv[1]);
if ( (int)islogopen(v4) < 0 )
{
fprintf(stdout, "Error opening log: %d\n", iserrno);
exit(-1);
}
puts("Recovering... Please wait");
if ( (unsigned int)isrecover() )
printf("Recovery failed with error %d\n", iserrno);
else
puts("Recovery SUCCESSFUL!");
islogclose();
return 0;
}

original_code:
int
main (int iArgc, char **ppcArgv)
{
 int iResult;
 char cLogfileName [100];
 if (iArgc != 2)
 {
  printf ("Usage: %s <LOGFILE>\n", ppcArgv [0]);
  exit (1);
 }
 sprintf (cLogfileName, "%s", ppcArgv [1]);
 iResult = islogopen (cLogfileName);
 if (iResult < 0)
 {
  fprintf (stdout, "Error opening log: %d\n", iserrno);
  exit (-1);
 }
 printf ("Recovering... Please wait\n");
 iResult = isrecover ();
 if (iResult)
  printf ("Recovery failed with error %d\n", iserrno);
 else
  printf ("Recovery SUCCESSFUL!\n");
 islogclose ();
 return (0);
}

canonical_original_code:
int main(int iArgc, char **ppcArgv)
{
 int iResult;
 char cLogfileName[100];
 if (iArgc != 2)
 {
  printf ("Usage: %s <LOGFILE>\n", ppcArgv [0]);
  exit (1);
 }
 sprintf (cLogfileName, "%s", ppcArgv [1]);
 iResult = islogopen (cLogfileName);
 if (iResult < 0)
 {
  fprintf (stdout, "Error opening log: %d\n", iserrno);
  exit (-1);
 }
 printf ("Recovering... Please wait\n");
 iResult = isrecover ();
 if (iResult)
  printf ("Recovery failed with error %d\n", iserrno);
 else
  printf ("Recovery SUCCESSFUL!\n");
 islogclose ();
 return (0);
}

variable_types: iArgc int

variable_types:
ppcArgv
char **

variable_types: iResult int

variable_types:
cLogfileName
char [100]


repo: gdawg/scantool-ubuntu

decompiled_code:
__int64 __fastcall nostretch_icon_proc(int a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int *v5; // rdi

if ( a1 != 3 )
return (unsigned int)d_button_proc();
v2 = *(_DWORD *)(a2 + 36);
v3 = v2 & 0x10;
if ( (v2 & 0x10) != 0 )
return (unsigned int)d_button_proc();
v5 = *(unsigned int **)(a2 + 48);
if ( *(_QWORD *)(a2 + 56) && (v2 & 4) != 0 )
v5 = *(unsigned int **)(a2 + 56);
if ( *(_QWORD *)(a2 + 64) && (v2 & 2) != 0 )
v5 = *(unsigned int **)(a2 + 64);
blit(v5, screen, 0LL, 0LL, *(unsigned int *)(a2 + 8), *(unsigned int *)(a2 + 12), *v5, v5[1]);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
unsigned int *v5; // rdi

if ( a1 != 3 )
return (unsigned int)d_button_proc();
v2 = *(_DWORD *)(a2 + 36);
v3 = v2 & 0x10;
if ( (v2 & 0x10) != 0 )
return (unsigned int)d_button_proc();
v5 = *(unsigned int **)(a2 + 48);
if ( *(_QWORD *)(a2 + 56) && (v2 & 4) != 0 )
v5 = *(unsigned int **)(a2 + 56);
if ( *(_QWORD *)(a2 + 64) && (v2 & 2) != 0 )
v5 = *(unsigned int **)(a2 + 64);
blit(v5, screen, 0LL, 0LL, *(unsigned int *)(a2 + 8), *(unsigned int *)(a2 + 12), *v5, v5[1]);
return v3;
}

original_code:
int nostretch_icon_proc(int msg, DIALOG *d, int c)
{
   BITMAP *butimage = (BITMAP *)d->dp;
   int butx;
   int buty;
   if ((msg == 3) && (!(d->flags & 16)))
   {
      if ((d->dp2 != ((void *)0)) && (d->flags & 4))
      {
      butimage = (BITMAP *)d->dp2;
      }
      if ((d->dp3 != ((void *)0)) && (d->flags & 2))
      {
      butimage = (BITMAP *)d->dp3;
      }
      butx = butimage->w;
      buty = butimage->h;
      blit(butimage, screen, 0, 0, d->x, d->y, butimage->w, butimage->h);
      return 0;
   }
   return d_button_proc(msg, d, c);
}

canonical_original_code:
int nostretch_icon_proc(int msg, struct DIALOG *d, int c)
{
   struct BITMAP *butimage = (BITMAP *)d->dp;
   int butx;
   int buty;
   if ((msg == 3) && (!(d->flags & 16)))
   {
      if ((d->dp2 != ((void *)0)) && (d->flags & 4))
      {
      butimage = (struct BITMAP *)d->dp2;
      }
      if ((d->dp3 != ((void *)0)) && (d->flags & 2))
      {
      butimage = (struct BITMAP *)d->dp3;
      }
      butx = butimage->w;
      buty = butimage->h;
      blit(butimage, screen, 0, 0, d->x, d->y, butimage->w, butimage->h);
      return 0;
   }
   return d_button_proc(msg, d, c);
}

variable_types: msg int

variable_types: struct DIALOG { int (*proc)(int msg, struct DIALOG *d, int c); int x; int fg; int key; int flags; int d1; void *dp; } *

variable_types: c int

variable_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; } *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH { short w; unsigned char dat[]; } *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D { int x; int u; int c; } *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f { float x; float u; int c; } *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); } *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; } *

variable_types: butx int

variable_types: buty int

user_defined_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; }

user_defined_types: struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); }


decompiled_code:
__int64 __fastcall super_textbox_proc(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r13
__int64 v5; // r14
int v6; // er15
__int64 v7; // rcx
__int64 result; // rax
int v9; // er15
int v10; // edx

v4 = font;
if ( *(_QWORD *)(a2 + 56) )
font = *(_QWORD *)(a2 + 56);
v5 = gui_mg_color;
if ( (*(_BYTE *)(a2 + 36) & 0x20) == 0 )
v5 = *(unsigned int *)(a2 + 24);
v6 = *(_DWORD *)(a2 + 20);
v7 = (unsigned int)text_height(font);
if ( a1 == 3 )
{
v9 = (v6 - 8) / (int)v7;
draw_textbox(
*(_QWORD *)(a2 + 48),
a2 + 40,
0LL,
*(unsigned int *)(a2 + 44),
(*(_DWORD *)(a2 + 36) & 2) == 0,
8LL,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
*(unsigned int *)(a2 + 16),
*(unsigned int *)(a2 + 20),
*(_DWORD *)(a2 + 36) & 0x20,
0LL,
0LL,
0LL);
v10 = 12;
if ( *(_DWORD *)(a2 + 40) <= v9 )
{
*(_DWORD *)(a2 + 44) = 0;
v10 = 0;
}
draw_textbox(
*(_QWORD *)(a2 + 48),
a2 + 40,
1LL,
*(unsigned int *)(a2 + 44),
(*(_DWORD *)(a2 + 36) & 2) == 0,
8LL,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
(unsigned int)(*(_DWORD *)(a2 + 16) - v10),
*(unsigned int *)(a2 + 20),
*(_DWORD *)(a2 + 36) & 0x20,
v5,
*(unsigned int *)(a2 + 28),
gui_mg_color);
result = *(unsigned int *)(a2 + 32);
if ( (_DWORD)result )
{
draw_scrollable_frame(
a2,
*(unsigned int *)(a2 + 40),
*(unsigned int *)(a2 + 44),
(unsigned int)v9,
(unsigned int)v5,
*(unsigned int *)(a2 + 28));
result = 0LL;
}
}
else
{
result = d_textbox_proc(a1, a2, a3, v7);
}
font = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // r13
__int64 v5; // r14
int v6; // er15
__int64 v7; // rcx
__int64 result; // rax
int v9; // er15
int v10; // edx

v4 = font;
if ( *(_QWORD *)(a2 + 56) )
font = *(_QWORD *)(a2 + 56);
v5 = gui_mg_color;
if ( (*(_BYTE *)(a2 + 36) & 0x20) == 0 )
v5 = *(unsigned int *)(a2 + 24);
v6 = *(_DWORD *)(a2 + 20);
v7 = (unsigned int)text_height(font);
if ( a1 == 3 )
{
v9 = (v6 - 8) / (int)v7;
draw_textbox(
*(_QWORD *)(a2 + 48),
a2 + 40,
0LL,
*(unsigned int *)(a2 + 44),
(*(_DWORD *)(a2 + 36) & 2) == 0,
8LL,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
*(unsigned int *)(a2 + 16),
*(unsigned int *)(a2 + 20),
*(_DWORD *)(a2 + 36) & 0x20,
0LL,
0LL,
0LL);
v10 = 12;
if ( *(_DWORD *)(a2 + 40) <= v9 )
{
*(_DWORD *)(a2 + 44) = 0;
v10 = 0;
}
draw_textbox(
*(_QWORD *)(a2 + 48),
a2 + 40,
1LL,
*(unsigned int *)(a2 + 44),
(*(_DWORD *)(a2 + 36) & 2) == 0,
8LL,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
(unsigned int)(*(_DWORD *)(a2 + 16) - v10),
*(unsigned int *)(a2 + 20),
*(_DWORD *)(a2 + 36) & 0x20,
v5,
*(unsigned int *)(a2 + 28),
gui_mg_color);
result = *(unsigned int *)(a2 + 32);
if ( (_DWORD)result )
{
draw_scrollable_frame(
a2,
*(unsigned int *)(a2 + 40),
*(unsigned int *)(a2 + 44),
(unsigned int)v9,
(unsigned int)v5,
*(unsigned int *)(a2 + 28));
result = 0LL;
}
}
else
{
result = d_textbox_proc(a1, a2, a3, v7);
}
font = v4;
return result;
}

original_code:
int super_textbox_proc(int msg, DIALOG *d, int c)
{
   int height, bar;
   int fg_color;
   int ret = 0;
   FONT *old_font = font;
   if (d->dp2)
      font = (FONT *)d->dp2;
   fg_color = (d->flags & 32) ? gui_mg_color : d->fg;
   height = (d->h-8) / text_height(font);
   if (msg == 3)
   {
      _draw_textbox(d->dp, &d->d1,
                0,
                d->d2, !(d->flags & 2), 8,
                d->x, d->y, d->w, d->h,
                (d->flags & 32),
                0, 0, 0);
      if (d->d1 > height) {
         bar = 12;
      }
      else {
         bar = 0;
         d->d2 = 0;
      }
      _draw_textbox(d->dp, &d->d1, 1, d->d2,
                !(d->flags & 2), 8,
                d->x, d->y, d->w-bar, d->h,
                (d->flags & 32),
                fg_color, d->bg, gui_mg_color);
      if (d->key)
         _draw_scrollable_frame(d, d->d1, d->d2, height, fg_color, d->bg);
   }
   else
      ret = d_textbox_proc(msg, d, c);
   font = old_font;
   return ret;
}

canonical_original_code:
int super_textbox_proc(int msg, struct DIALOG *d, int c)
{
   int height; int bar;
   int fg_color;
   int ret = 0;
   struct FONT *old_font = font;
   if (d->dp2)
      font = (struct FONT *)d->dp2;
   fg_color = (d->flags & 32) ? gui_mg_color : d->fg;
   height = (d->h-8) / text_height(font);
   if (msg == 3)
   {
      _draw_textbox(d->dp, &d->d1,
                0,
                d->d2, !(d->flags & 2), 8,
                d->x, d->y, d->w, d->h,
                (d->flags & 32),
                0, 0, 0);
      if (d->d1 > height) {
         bar = 12;
      }
      else {
         bar = 0;
         d->d2 = 0;
      }
      _draw_textbox(d->dp, &d->d1, 1, d->d2,
                !(d->flags & 2), 8,
                d->x, d->y, d->w-bar, d->h,
                (d->flags & 32),
                fg_color, d->bg, gui_mg_color);
      if (d->key)
         _draw_scrollable_frame(d, d->d1, d->d2, height, fg_color, d->bg);
   }
   else
      ret = d_textbox_proc(msg, d, c);
   font = old_font;
   return ret;
}

variable_types: height int

variable_types: bar int

variable_types: ret int

variable_types: struct FONT { void *data; int height; struct FONT_VTABLE { int (*font_height)(struct FONT *f); int (*char_length)(struct FONT *f, int ch); int (*text_length)(struct FONT *f, char *text); int (*render_char)(struct FONT *f, int ch, int fg, int bg, struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; } *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH { short w; unsigned char dat[]; } *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D { int x; int u; int c; } *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f { float x; float u; int c; } *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); } *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; } *bmp, int x, int y); void (*render)(struct FONT *f, char *text, int fg, int bg, struct BITMAP *bmp, int x, int y); void (*destroy)(struct FONT *f); int (*get_font_ranges)(struct FONT *f); int (*get_font_range_begin)(struct FONT *f, int range); int (*get_font_range_end)(struct FONT *f, int range); struct FONT *(*extract_font_range)(struct FONT *f, int begin, int end); struct FONT *(*merge_fonts)(struct FONT *f1, struct FONT *f2); int (*transpose_font)(struct FONT *f, int drange); } *vtable; } *

user_defined_types: struct DIALOG { int (*proc)(int msg, struct DIALOG *d, int c); int x; int fg; int key; int flags; int d1; void *dp; }

user_defined_types: struct FONT { void *data; int height; struct FONT_VTABLE *vtable; }

user_defined_types: struct FONT_VTABLE { int (*font_height)(struct FONT *f); int (*char_length)(struct FONT *f, int ch); int (*text_length)(struct FONT *f, char *text); int (*render_char)(struct FONT *f, int ch, int fg, int bg, struct BITMAP *bmp, int x, int y); void (*render)(struct FONT *f, char *text, int fg, int bg, struct BITMAP *bmp, int x, int y); void (*destroy)(struct FONT *f); int (*get_font_ranges)(struct FONT *f); int (*get_font_range_begin)(struct FONT *f, int range); int (*get_font_range_end)(struct FONT *f, int range); struct FONT *(*extract_font_range)(struct FONT *f, int begin, int end); struct FONT *(*merge_fonts)(struct FONT *f1, struct FONT *f2); int (*transpose_font)(struct FONT *f, int drange); }


decompiled_code:
__int64 __fastcall st_ctext_proc(int a1, __int64 a2)
{
__int64 v3; // r8
__int64 v4; // rbx

if ( a1 != 3 )
return 0LL;
v3 = gui_mg_color;
if ( (*(_BYTE *)(a2 + 36) & 0x20) == 0 )
v3 = *(unsigned int *)(a2 + 24);
v4 = font;
if ( *(_QWORD *)(a2 + 56) )
font = *(_QWORD *)(a2 + 56);
gui_textout_ex(
screen,
*(_QWORD *)(a2 + 48),
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
v3,
*(unsigned int *)(a2 + 28),
-1LL);
font = v4;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
__int64 v3; // r8
__int64 v4; // rbx

if ( a1 != 3 )
return 0LL;
v3 = gui_mg_color;
if ( (*(_BYTE *)(a2 + 36) & 0x20) == 0 )
v3 = *(unsigned int *)(a2 + 24);
v4 = font;
if ( *(_QWORD *)(a2 + 56) )
font = *(_QWORD *)(a2 + 56);
gui_textout_ex(
screen,
*(_QWORD *)(a2 + 48),
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
v3,
*(unsigned int *)(a2 + 28),
-1LL);
font = v4;
return 0LL;
}

original_code:
int st_ctext_proc(int msg, DIALOG *d, int c)
{
   ;
   if (msg==3)
   {
      int fg = (d->flags & 32) ? gui_mg_color : d->fg;
      FONT *oldfont = font;
      if (d->dp2)
      font = d->dp2;
      gui_textout_ex(screen, d->dp, d->x, d->y, fg, d->bg, -1);
      font = oldfont;
   }
   return 0;
}

canonical_original_code:
int st_ctext_proc(int msg, struct DIALOG *d, int c)
{
   ;
   if (msg==3)
   {
      int fg = (d->flags & 32) ? gui_mg_color : d->fg;
      struct FONT *oldfont = font;
      if (d->dp2)
      font = d->dp2;
      gui_textout_ex(screen, d->dp, d->x, d->y, fg, d->bg, -1);
      font = oldfont;
   }
   return 0;
}

variable_types: fg int

user_defined_types: struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; }

user_defined_types: struct FONT_GLYPH { short w; unsigned char dat[]; }

user_defined_types: struct V3D_f { float x; float u; int c; }


decompiled_code:
__int64 __fastcall caption_proc(int a1, __int64 a2)
{
if ( a1 == 1 )
*(_QWORD *)(a2 + 56) = *(_QWORD *)(datafile + 96);
return st_ctext_proc(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
if ( a1 == 1 )
*(_QWORD *)(a2 + 56) = *(_QWORD *)(datafile + 96);
return func2(a1, a2);
}

original_code:
int caption_proc(int msg, DIALOG *d, int c)
{
   if (msg == 1)
   {
      d->dp2 = datafile[3].dat;
   }
   return st_ctext_proc(msg, d, c);
}

canonical_original_code:
int caption_proc(int msg, struct DIALOG *d, int c)
{
   if (msg == 1)
   {
      d->dp2 = datafile[3].dat;
   }
   return st_ctext_proc(msg, d, c);
}


decompiled_code:
void __fastcall __noreturn fatal_error(const char *a1)
{
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

if ( datafile )
unload_datafile();
sprintf(v1, "\nERROR: %s", a1);
strcat(v1, "\n\nPlease contact ScanTool.net via our website at http://www.ScanTool.net/support");
strcat(v1, "\nInclude the following information:");
strcat(v1, "\n\t- Exact error message");
strcat(v1, "\n\t- CPU type/speed, i.e. \"Pentium 100Mhz\"");
strcat(v1, "\n\t- OS, i.e. \"Windows 95\"");
strcat(v1, "\n\t- Total amount of RAM installed, i.e. \"4Mb\"\n\n");
allegro_message(v1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
char v1[520]; // [rsp+0h] [rbp-208h] BYREF

if ( datafile )
unload_datafile();
sprintf(v1, "\nERROR: %s", a1);
strcat(v1, "\n\nPlease contact ScanTool.net via our website at http://www.ScanTool.net/support");
strcat(v1, "\nInclude the following information:");
strcat(v1, "\n\t- Exact error message");
strcat(v1, "\n\t- CPU type/speed, i.e. \"Pentium 100Mhz\"");
strcat(v1, "\n\t- OS, i.e. \"Windows 95\"");
strcat(v1, "\n\t- Total amount of RAM installed, i.e. \"4Mb\"\n\n");
allegro_message(v1);
exit(1);
}

original_code:
void fatal_error(char *msg)
{
   char temp_buf[512];
   if (datafile != ((void *)0))
      unload_datafile(datafile);
   sprintf(temp_buf, "\nERROR: %s", msg);
   strcat(temp_buf, "\n\nPlease contact ScanTool.net via our website at http://www.ScanTool.net/support");
   strcat(temp_buf, "\nInclude the following information:");
   strcat(temp_buf, "\n\t- Exact error message");
   strcat(temp_buf, "\n\t- CPU type/speed, i.e. \"Pentium 100Mhz\"");
   strcat(temp_buf, "\n\t- OS, i.e. \"Windows 95\"");
   strcat(temp_buf, "\n\t- Total amount of RAM installed, i.e. \"4Mb\"\n\n");
   allegro_message(temp_buf);
   exit(1);
}

variable_types:
msg
char *


repo: gdestuynder/audisp-cef

original_code:
static int nv_split(char *buf, struct nv_pair *nv)
{
 char *ptr;
 nv->name = ((void *)0);
 nv->value = ((void *)0);
 nv->option = ((void *)0);
 ptr = strtok(buf, " ");
 if (ptr == ((void *)0))
  return 0;
 if (ptr[0] == '#')
  return 0;
 nv->name = ptr;
 ptr = strtok(((void *)0), " ");
 if (ptr == ((void *)0))
  return 1;
 if (strcmp(ptr, "=") != 0)
  return 2;
 ptr = strtok(((void *)0), " ");
 if (ptr == ((void *)0))
  return 1;
 nv->value = ptr;
 ptr = strtok(((void *)0), " ");
 if (ptr) {
  nv->option = ptr;
  ptr = strtok(((void *)0), " ");
  if (ptr)
   return 1;
 }
 return 0;
}

variable_types:
buf
char *

variable_types: struct nv_pair { char *name; char *value; char *option; } *

variable_types:
ptr
char *


decompiled_code:
char **__fastcall kw_lookup(char *s2)
{
const char **v2; // rbx
int v3; // ebp
const char *v4; // rdi

v2 = (const char **)&keywords;
v3 = 0;
v4 = "remote_server";
do
{
if ( !strcasecmp(v4, s2) )
break;
++v3;
v2 += 3;
v4 = *v2;
}
while ( *v2 );
return &(&keywords)[3 * v3];
}

canonical_decompiled_code:
char **__fastcall func1(char *s2)
{
const char **v2; // rbx
int v3; // ebp
const char *v4; // rdi

v2 = (const char **)&keywords;
v3 = 0;
v4 = "remote_server";
do
{
if ( !strcasecmp(v4, s2) )
break;
++v3;
v2 += 3;
v4 = *v2;
}
while ( *v2 );
return &(&keywords)[3 * v3];
}

original_code:
static const struct kw_pair *kw_lookup(const char *val)
{
 int i = 0;
 while (keywords[i].name != ((void *)0)) {
  if (strcasecmp(keywords[i].name, val) == 0)
   break;
  i++;
 }
 return &keywords[i];
}

canonical_original_code:
static struct kw_pair *kw_lookup(char *val)
{
 int i = 0;
 while (keywords[i].name != ((void *)0)) {
  if (strcasecmp(keywords[i].name, val) == 0)
   break;
  i++;
 }
 return &keywords[i];
}

variable_types:
val
char *

variable_types: i int

return_type: struct kw_pair { char *name; int (*parser)(struct nv_pair { char *name; char *value; char *option; } *, int, struct cef_conf { char *remote_server; unsigned int port; unsigned int facility; } *); int max_options; } *

user_defined_types: struct kw_pair { char *name; int (*parser)(struct nv_pair *, int, struct cef_conf *); int max_options; }


decompiled_code:
__int64 __fastcall port_parser(__int64 a1, unsigned int a2, __int64 a3)
{
return parse_uint(a1, a2, (unsigned int *)(a3 + 8), 0, 0x7FFFFFFFu);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, __int64 a3)
{
return func2(a1, a2, (unsigned int *)(a3 + 8), 0, 0x7FFFFFFFu);
}

original_code:
static int port_parser(struct nv_pair *nv, int line, cef_conf_t *config)
{
 return parse_uint (nv, line, &(config->port), 0, 0x7fffffff);
}

canonical_original_code:
static int port_parser(struct nv_pair *nv, int line, struct cef_conf *config)
{
 return parse_uint (nv, line, &(config->port), 0, 0x7fffffff);
}

variable_types: line int

variable_types: struct cef_conf { char *remote_server; unsigned int port; unsigned int facility; } *

user_defined_types: struct nv_pair { char *name; char *value; char *option; }


decompiled_code:
__int64 __fastcall server_parser(__int64 a1, __int64 a2, char **a3)
{
const char *v3; // rdi

v3 = *(const char **)(a1 + 8);
if ( v3 )
*a3 = strdup(v3);
else
*a3 = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, char **a3)
{
const char *v3; // rdi

v3 = *(const char **)(a1 + 8);
if ( v3 )
*a3 = strdup(v3);
else
*a3 = 0LL;
return 0LL;
}

original_code:
static int server_parser(struct nv_pair *nv, int line,
  cef_conf_t *config)
{
 if (nv->value)
  config->remote_server = strdup(nv->value);
 else
  config->remote_server = ((void *)0);
 return 0;
}

canonical_original_code:
static int server_parser(struct nv_pair *nv, int line, struct cef_conf *config)
{
 if (nv->value)
  config->remote_server = strdup(nv->value);
 else
  config->remote_server = ((void *)0);
 return 0;
}

user_defined_types: struct cef_conf { char *remote_server; unsigned int port; unsigned int facility; }


original_code:
void clear_config(cef_conf_t *config)
{
 config->remote_server = ((void *)0);
 config->port = 514;
 config->facility = (21<<3);
}

canonical_original_code:
void clear_config(struct cef_conf *config)
{
 config->remote_server = ((void *)0);
 config->port = 514;
 config->facility = (21<<3);
}


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

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

original_code:
void free_config(cef_conf_t *config)
{
 free((void *)config->remote_server);
}

canonical_original_code:
void free_config(struct cef_conf *config)
{
 free((void *)config->remote_server);
}


repo: gdickinson/compilerclass

decompiled_code:
void init_tac()
{
current_temp = 0;
current_label = 0;
next_label = -1;
}

canonical_decompiled_code:
void func0()
{
current_temp = 0;
current_label = 0;
next_label = -1;
}


gen

decompiled_code:
__int64 __fastcall gen(__int64 a1, _QWORD *a2)
{
if ( *a2 )
list_append(*a2, a1);
else
*a2 = list_create(a1);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
if ( *a2 )
list_append(*a2, a1);
else
*a2 = list_create(a1);
return a1;
}

original_code:
char* gen(char* code, node** n) {
    if (*n == ((void *)0)) {
        *n = list_create(code);
    } else {
        list_append(*n, code);
    }
    return code;
}

canonical_original_code:
char *gen(char *code, struct node **n) {
    if (*n == ((void *)0)) {
        *n = list_create(code);
    } else {
        list_append(*n, code);
    }
    return code;
}

variable_types:
code
char *

variable_types: struct node { void *data; struct node *next; } **

return_type: char *


decompiled_code:
char *__fastcall gen2(const char *a1, const char *a2, _QWORD *a3)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s", a1, a2);
gen((__int64)ptr, a3);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, const char *a2, _QWORD *a3)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s", a1, a2);
func1((__int64)ptr, a3);
return ptr;
}

original_code:
char* gen2(char* s1, char* s2, node** n) {
    char* c;
    asprintf(&c, "%s %s", s1, s2);
    gen(c, n);
    return c;
}

canonical_original_code:
char *gen2(char *s1, char *s2, struct node **n) {
    char *c;
    asprintf(&c, "%s %s", s1, s2);
    gen(c, n);
    return c;
}

variable_types:
c
char *

user_defined_types: struct node { void *data; struct node *next; }


decompiled_code:
char *__fastcall gen3(const char *a1, const char *a2, const char *a3, _QWORD *a4)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s", a1, a2, a3);
gen((__int64)ptr, a4);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1, const char *a2, const char *a3, _QWORD *a4)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s", a1, a2, a3);
func1((__int64)ptr, a4);
return ptr;
}

original_code:
char* gen3(char* s1, char* s2, char* s3, node** n) {
    char* c;
    asprintf(&c, "%s %s %s", s1, s2, s3);
    gen(c, n);
    return c;
}

canonical_original_code:
char *gen3(char *s1, char *s2, char *s3, struct node **n) {
    char *c;
    asprintf(&c, "%s %s %s", s1, s2, s3);
    gen(c, n);
    return c;
}


decompiled_code:
char *__fastcall gen4(const char *a1, const char *a2, const char *a3, const char *a4, _QWORD *a5)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s %s", a1, a2, a3, a4);
gen((__int64)ptr, a5);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1, const char *a2, const char *a3, const char *a4, _QWORD *a5)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s %s", a1, a2, a3, a4);
func1((__int64)ptr, a5);
return ptr;
}

original_code:
char* gen4(char* s1, char* s2, char* s3, char* s4, node** n) {
    char* c;
    asprintf(&c, "%s %s %s %s", s1, s2, s3, s4);
    gen(c, n);
    return c;
}

canonical_original_code:
char *gen4(char *s1, char *s2, char *s3, char *s4, struct node **n) {
    char *c;
    asprintf(&c, "%s %s %s %s", s1, s2, s3, s4);
    gen(c, n);
    return c;
}


decompiled_code:
char *__fastcall gen5(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, _QWORD *a6)
{
char *ptr; // [rsp+10h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s %s %s", a1, a2, a3, a4, a5);
gen((__int64)ptr, a6);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func5(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, _QWORD *a6)
{
char *ptr; // [rsp+10h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s %s %s", a1, a2, a3, a4, a5);
func1((__int64)ptr, a6);
return ptr;
}

original_code:
char* gen5(char* s1, char* s2, char* s3, char* s4, char* s5, node** n) {
    char* c;
    asprintf(&c, "%s %s %s %s %s", s1, s2, s3, s4, s5);
    gen(c, n);
    return c;
}

canonical_original_code:
char *gen5(char *s1, char *s2, char *s3, char *s4, char *s5, struct node **n) {
    char *c;
    asprintf(&c, "%s %s %s %s %s", s1, s2, s3, s4, s5);
    gen(c, n);
    return c;
}


decompiled_code:
char *__fastcall gen6(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, const char *a6, _QWORD *a7)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s %s %s %s", a1, a2, a3, a4, a5, a6);
gen((__int64)ptr, a7);
return ptr;
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1, const char *a2, const char *a3, const char *a4, const char *a5, const char *a6, _QWORD *a7)
{
char *ptr; // [rsp+8h] [rbp-10h] BYREF

asprintf(&ptr, "%s %s %s %s %s %s", a1, a2, a3, a4, a5, a6);
func1((__int64)ptr, a7);
return ptr;
}

original_code:
char* gen6(char* s1, char* s2, char* s3, char* s4, char* s5, char* s6, node** n) {
    char* c;
    asprintf(&c, "%s %s %s %s %s %s", s1, s2, s3, s4, s5, s6);
    gen(c, n);
    return c;
}

canonical_original_code:
char *gen6(char *s1, char *s2, char *s3, char *s4, char *s5, char *s6, struct node **n) {
    char *c;
    asprintf(&c, "%s %s %s %s %s %s", s1, s2, s3, s4, s5, s6);
    gen(c, n);
    return c;
}


temp

decompiled_code:
char *temp()
{
int v0; // eax
char *v1; // rbx

v0 = snprintf(0LL, 0LL, "t%d", (unsigned int)current_temp);
v1 = (char *)malloc(v0 + 1);
sprintf(v1, "t%d", (unsigned int)++current_temp);
return v1;
}

canonical_decompiled_code:
char *func7()
{
int v0; // eax
char *v1; // rbx

v0 = snprintf(0LL, 0LL, "t%d", (unsigned int)current_temp);
v1 = (char *)malloc(v0 + 1);
sprintf(v1, "t%d", (unsigned int)++current_temp);
return v1;
}

original_code:
char* temp() {
  char* s = malloc(snprintf(((void *)0), 0, "t%d", current_temp) + 1);
  sprintf(s, "t%d", ++current_temp);
  return s;
}

canonical_original_code:
char *temp() {
  char *s = malloc(snprintf(((void *)0), 0, "t%d", current_temp) + 1);
  sprintf(s, "t%d", ++current_temp);
  return s;
}

variable_types:
s
char *


decompiled_code:
int __fastcall print_code(const char *a1)
{
return puts(a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return puts(a1);
}

original_code:
void print_code(char* code) {
    printf("%s\n", code);
}

canonical_original_code:
void print_code(char *code) {
    printf("%s\n", code);
}


decompiled_code:
int __fastcall print_node(const char *a1)
{
return print_code(a1);
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
return func8(a1);
}

original_code:
void print_node(void* v) {
    char* c = (char*) v;
    print_code(c);
}

canonical_original_code:
void print_node(void *v) {
    char *c = (char*) v;
    print_code(c);
}

variable_types:
v
void *


decompiled_code:
__int64 __fastcall print_tac(__int64 a1)
{
if ( !a1 )
puts("print_tac called on null");
return list_foreach(a1, print_node);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
if ( !a1 )
puts("print_tac called on null");
return list_foreach(a1, print_node);
}

original_code:
void print_tac(node* n) {
    if (n == ((void *)0)) { printf("print_tac called on null\n"); }
    list_foreach(n, print_node);
}

canonical_original_code:
void print_tac(struct node *n) {
    if (n == ((void *)0)) { printf("print_tac called on null\n"); }
    list_foreach(n, print_node);
}

variable_types: struct node { void *data; struct node *next; } *


nextlabel

decompiled_code:
char *nextlabel()
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

sprintf(s, "L%d", (unsigned int)++current_label);
return strdup(s);
}

canonical_decompiled_code:
char *func11()
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

sprintf(s, "L%d", (unsigned int)++current_label);
return strdup(s);
}

original_code:
char* nextlabel() {
    char b[10];
    sprintf(b, "L%d", ++current_label);
    return strdup(b);
}

canonical_original_code:
char *nextlabel() {
    char b[10];
    sprintf(b, "L%d", ++current_label);
    return strdup(b);
}

variable_types:
b
char [10]


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

if ( a2 )
result = list_append(a2, a1);
else
result = list_create(a1);
return result;
}

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

if ( a2 )
result = list_append(a2, a1);
else
result = list_create(a1);
return result;
}

original_code:
void append_code(char* code, node* n) {
    if (n == ((void *)0)) {
        n = list_create(code);
    } else {
        list_append(n, code);
    }
}

canonical_original_code:
void append_code(char *code, struct node *n) {
    if (n == ((void *)0)) {
        n = list_create(code);
    } else {
        list_append(n, code);
    }
}


label

decompiled_code:
void __fastcall label(int a1)
{
next_label = a1;
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
next_label = a1;
}

original_code:
void label(int l) {
    next_label = l;
}

canonical_original_code:
void label(int l) {
    next_label = l;
}

variable_types: l int


decompiled_code:
int __fastcall find_symbol(const char **a1, const char *a2)
{
return strcmp(*a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(const char **a1, const char *a2)
{
return strcmp(*a1, a2);
}

original_code:
int find_symbol(void* testsymbol, void* targetname) {
    symbol* s1 = (symbol*) testsymbol;
    char* id1 = s1->name;
    return (strcmp(id1, targetname));
}

canonical_original_code:
int find_symbol(void *testsymbol, void *targetname) {
    struct symbol *s1 = (symbol*) testsymbol;
    char *id1 = s1->name;
    return (strcmp(id1, targetname));
}

variable_types:
testsymbol
void *

variable_types:
targetname
void *

variable_types: struct symbol { char *name; struct symbol *type; char *label; } *


decompiled_code:
__int64 __fastcall print_symbol_table(const void **a1)
{
printf("Printing scope at %p (parent = %p):\n", a1, *a1);
list_foreach(a1[2], print_symbol);
putchar(10);
return list_foreach(a1[1], print_symbol_table);
}

canonical_decompiled_code:
__int64 __fastcall func1(const void **a1)
{
printf("Printing scope at %p (parent = %p):\n", a1, *a1);
list_foreach(a1[2], print_symbol);
putchar(10);
return list_foreach(a1[1], print_symbol_table);
}

original_code:
void print_symbol_table(void* rootscope) {
    scope* castedscope = (scope*) rootscope;
    printf("Printing scope at %p (parent = %p):\n", castedscope, castedscope->parent);
    list_foreach(castedscope->symbol_list, print_symbol);
    printf("\n");
    list_foreach(castedscope->children, print_symbol_table);
}

canonical_original_code:
void print_symbol_table(void *rootscope) {
    struct scope *castedscope = (scope*) rootscope;
    printf("Printing scope at %p (parent = %p):\n", castedscope, castedscope->parent);
    list_foreach(castedscope->symbol_list, print_symbol);
    printf("\n");
    list_foreach(castedscope->children, print_symbol_table);
}

variable_types:
rootscope
void *

variable_types: struct scope { struct scope *parent; struct node { void *data; struct node *next; } *children; struct node *symbol_list; } *

user_defined_types: struct scope { struct scope *parent; struct node *children; struct node *symbol_list; }


decompiled_code:
void __fastcall add_symbol_to_scope(__int64 a1, __int64 a2)
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 16) )
list_append();
else
*(_QWORD *)(a1 + 16) = list_create(a2);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
if ( a1 )
{
if ( *(_QWORD *)(a1 + 16) )
list_append();
else
*(_QWORD *)(a1 + 16) = list_create(a2);
}
}

original_code:
void add_symbol_to_scope(scope* s, symbol* symbol) {
    if (s == ((void *)0)) {
        return;
    }
    if (!s->symbol_list) {
        s->symbol_list = list_create(symbol);
    } else {
        list_append(s->symbol_list, symbol);
    }
}

canonical_original_code:
void add_symbol_to_scope(struct scope *s, struct symbol *symbol) {
    if (s == ((void *)0)) {
        return;
    }
    if (!s->symbol_list) {
        s->symbol_list = list_create(symbol);
    } else {
        list_append(s->symbol_list, symbol);
    }
}

user_defined_types: struct symbol { char *name; struct symbol *type; char *label; }


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

result = a1;
if ( *(_QWORD *)(a1 + 8) != a1 )
result = reduce_type(*(_QWORD *)(a1 + 8));
return result;
}

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

result = a1;
if ( *(_QWORD *)(a1 + 8) != a1 )
result = func3(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
symbol* reduce_type(symbol*s) {
    if (s->type == s) {
        return s;
    } else {
        return reduce_type(s->type);
    }
}

canonical_original_code:
struct symbol *reduce_type(struct symbol *s) {
    if (s->type == s) {
        return s;
    } else {
        return reduce_type(s->type);
    }
}

variable_types:
s
struct symbol *

return_type: struct symbol { char *name; struct symbol *type; char *label; } *


decompiled_code:
void __fastcall print_symbol(__int64 a1)
{
const char **v1; // rax

if ( a1 )
{
v1 = (const char **)reduce_type(a1);
printf("%s: %s (reduces to %s)\n", *(const char **)a1, **(const char ***)(a1 + 8), *v1);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
const char **v1; // rax

if ( a1 )
{
v1 = (const char **)func3(a1);
printf("%s: %s (reduces to %s)\n", *(const char **)a1, **(const char ***)(a1 + 8), *v1);
}
}

original_code:
void print_symbol(void* sym) {
    if (sym == ((void *)0)) {
        return;
    }
    symbol* s = (symbol*) sym;
    printf("%s: %s (reduces to %s)\n", s->name, s->type->name, reduce_type(s)->name);
}

canonical_original_code:
void print_symbol(void *sym) {
    if (sym == ((void *)0)) {
        return;
    }
    struct symbol *s = (symbol*) sym;
    printf("%s: %s (reduces to %s)\n", s->name, s->type->name, reduce_type(s)->name);
}

variable_types:
sym
void *


typecheck

decompiled_code:
int __fastcall typecheck(__int64 a1, __int64 a2)
{
const char **v2; // rbx
const char **v3; // rax

v2 = (const char **)reduce_type(a1);
v3 = (const char **)reduce_type(a2);
return strcmp(*v2, *v3);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
const char **v2; // rbx
const char **v3; // rax

v2 = (const char **)func3(a1);
v3 = (const char **)func3(a2);
return strcmp(*v2, *v3);
}

original_code:
int typecheck(symbol* type1, symbol* type2, scope* s) {
   symbol* prim1 = reduce_type(type1);
   symbol* prim2 = reduce_type(type2);
   return strcmp(prim1->name, prim2->name);
}

canonical_original_code:
int typecheck(struct symbol *type1, struct symbol *type2, struct scope *s) {
   struct symbol *prim1 = reduce_type(type1);
   struct symbol *prim2 = reduce_type(type2);
   return strcmp(prim1->name, prim2->name);
}


decompiled_code:
__int64 __fastcall list_merge(__int64 a1, __int64 *a2)
{
__int64 *i; // rbx

for ( i = a2; i; i = (__int64 *)i[1] )
list_append(a1, *i);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 *a2)
{
__int64 *i; // rbx

for ( i = a2; i; i = (__int64 *)i[1] )
list_append(a1, *i);
return a1;
}

original_code:
node* list_merge(node* a, node* b) {
    while (b != ((void *)0)) {
        list_append(a, b->data);
        b = b->next;
    }
    return a;
}

canonical_original_code:
struct node *list_merge(struct node *a, struct node *b) {
    while (b != ((void *)0)) {
        list_append(a, b->data);
        b = b->next;
    }
    return a;
}

variable_types:
a
struct node *

variable_types:
b
struct node *

return_type: struct node { void *data; struct node *next; } *


repo: geckojsc/nocta

decompiled_code:
__int64 __fastcall u8_to_fix(int a1)
{
return (unsigned int)(32 * a1);
}

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

original_code:
inline static int32_t u8_to_fix(int32_t x) {
 return x << (13 - 8);
}

canonical_original_code:
inline static int u8_to_fix(int x) {
 return x << (13 - 8);
}

variable_types: x int


decompiled_code:
__int64 __fastcall fix_mul(int a1, int a2)
{
return (unsigned int)((a2 * a1) >> 13);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
return (unsigned int)((a2 * a1) >> 13);
}

original_code:
inline static int32_t fix_mul(int32_t a, int32_t b) {
 return (a * b) >> 13;
}

canonical_original_code:
inline static int fix_mul(int a, int b) {
 return (a * b) >> 13;
}

variable_types: a int

variable_types: b int


original_code:
static int svfilter_run(filter_data* data, filter_state* s, int input) {
 int output = 0;
 for (int i=0; i<2; i++) {
  s->lp = s->lp + fix_mul(data->tuned_freq, s->bp);
  s->hp = input - s->lp - fix_mul(data->tuned_res, s->bp);
  s->bp = fix_mul(data->tuned_freq, s->hp) + s->bp;
  s->n = s->hp + s->lp;
  output += *s->out / 2;
 }
 return (output * data->vol) >> 8;
}

canonical_original_code:
static int svfilter_run(struct filter_data *data, struct filter_state *s, int input) {
 int output = 0;
 for (int i = 0; i<2; i++) {
  s->lp = s->lp + fix_mul(data->tuned_freq, s->bp);
  s->hp = input - s->lp - fix_mul(data->tuned_res, s->bp);
  s->bp = fix_mul(data->tuned_freq, s->hp) + s->bp;
  s->n = s->hp + s->lp;
  output += *s->out / 2;
 }
 return (output * data->vol) >> 8;
}

variable_types: struct filter_data { unsigned char vol; int mode; int freq; unsigned char res; int tuned_freq; int tuned_res; struct filter_state { int lp; int *out; } l; } *

variable_types:
s
struct filter_state *

variable_types: input int

variable_types: output int

variable_types: i int

user_defined_types: struct filter_data { unsigned char vol; int mode; int freq; unsigned char res; int tuned_freq; int tuned_res; struct filter_state l; }


decompiled_code:
__int64 __fastcall svfilter_r(__int64 a1, int a2)
{
return svfilter_run(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 48LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return func2(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 48LL, a2);
}

original_code:
static int svfilter_r(nocta_unit* self, int x) {
 filter_data* data = self->data;
 return svfilter_run(data, &data->r, x);
}

canonical_original_code:
static int svfilter_r(struct nocta_unit *self, int x) {
 struct filter_data *data = self->data;
 return svfilter_run(data, &data->r, x);
}

variable_types: struct nocta_unit { struct nocta_context { int sample_rate; } *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param { char *name; int min; int (*get)(struct nocta_unit *unit); void (*set)(struct nocta_unit *unit, int val); } *params; int num_params; } *

user_defined_types: struct nocta_unit { struct nocta_context *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param *params; int num_params; }

user_defined_types: struct filter_state { int lp; int *out; }


decompiled_code:
__int64 __fastcall svfilter_l(__int64 a1, int a2)
{
return svfilter_run(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 24LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2)
{
return func2(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 24LL, a2);
}

original_code:
static int svfilter_l(nocta_unit* self, int x) {
 filter_data* data = self->data;
 return svfilter_run(data, &data->l, x);
}

canonical_original_code:
static int svfilter_l(struct nocta_unit *self, int x) {
 struct filter_data *data = self->data;
 return svfilter_run(data, &data->l, x);
}

user_defined_types: struct nocta_context { int sample_rate; }

user_defined_types: struct nocta_param { char *name; int min; int (*get)(struct nocta_unit *unit); void (*set)(struct nocta_unit *unit, int val); }


decompiled_code:
__int64 __fastcall fix_sin(int a1)
{
return (unsigned int)(int)(sin((double)a1 * 0.0001220703125) * 8192.0);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return (unsigned int)(int)(sin((double)a1 * 0.0001220703125) * 8192.0);
}

original_code:
inline static int32_t fix_sin(int32_t x) {
 double y = (double)x / (1<<13);
 return sin(y) * (1<<13);
}

canonical_original_code:
inline static int fix_sin(int x) {
 double y = (double)x / (1<<13);
 return sin(y) * (1<<13);
}

variable_types: y double


original_code:
nocta_unit* nocta_svfilter(nocta_context* context) {
 nocta_unit* self = nocta_create_impl((nocta_unit) { .context = context, .name = "svfilter", .data = ialloc_impl(sizeof(filter_data), &(filter_data){ .vol = 255, .freq = 7000, .res = 0 }), .process_l = svfilter_l, .process_r = svfilter_r, .params = svfilter_params, .num_params = NOCTA_FILTER_NUM_PARAMS });
 set_mode(self, NOCTA_FILTER_MODE_LOWPASS);
 return self;
}

canonical_original_code:
struct nocta_unit *nocta_svfilter(struct nocta_context *context) {
 struct nocta_unit *self = nocta_create_impl((nocta_unit) { .context = context, .name = "svfilter", .data = ialloc_impl(sizeof(filter_data), &(filter_data){ .vol = 255, .freq = 7000, .res = 0 }), .process_l = svfilter_l, .process_r = svfilter_r, .params = svfilter_params, .num_params = NOCTA_FILTER_NUM_PARAMS });
 set_mode(self, NOCTA_FILTER_MODE_LOWPASS);
 return self;
}

variable_types:
context
struct nocta_context *

return_type: struct nocta_unit { struct nocta_context { int sample_rate; } *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param { char *name; int min; int (*get)(struct nocta_unit *unit); void (*set)(struct nocta_unit *unit, int val); } *params; int num_params; } *


decompiled_code:
__int64 __fastcall delay_r(__int64 a1, int a2)
{
return delay_run(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 40LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return func0(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 40LL, a2);
}

original_code:
static int delay_r(nocta_unit* self, int x) {
 delay_data* data = self->data;
 return delay_run(data, &data->r, x);
}

canonical_original_code:
static int delay_r(struct nocta_unit *self, int x) {
 struct delay_data *data = self->data;
 return delay_run(data, &data->r, x);
}

variable_types: struct delay_data { unsigned char dry; unsigned char feedback; int delay_time; struct delay_buffer { short *pre_samples; short *samples; int size; int i; } l; int sample_rate; } *

user_defined_types: struct delay_data { unsigned char dry; unsigned char feedback; int delay_time; struct delay_buffer l; int sample_rate; }


decompiled_code:
__int64 __fastcall delay_l(__int64 a1, int a2)
{
return delay_run(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 8LL, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
return func0(*(unsigned __int8 **)(a1 + 16), *(_QWORD *)(a1 + 16) + 8LL, a2);
}

original_code:
static int delay_l(nocta_unit* self, int x) {
 delay_data* data = self->data;
 return delay_run(data, &data->l, x);
}

canonical_original_code:
static int delay_l(struct nocta_unit *self, int x) {
 struct delay_data *data = self->data;
 return delay_run(data, &data->l, x);
}

user_defined_types: struct delay_buffer { short *pre_samples; short *samples; int size; int i; }


decompiled_code:
__int64 __fastcall get_dry(__int64 a1)
{
return **(unsigned __int8 **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return **(unsigned __int8 **)(a1 + 16);
}

original_code:
int get_dry(nocta_unit* self) {
 delay_data* data = self->data;
 return data->dry;
}

canonical_original_code:
int get_dry(struct nocta_unit *self) {
 struct delay_data *data = self->data;
 return data->dry;
}


decompiled_code:
__int64 __fastcall get_wet(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 16) + 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 16) + 1LL);
}

original_code:
int get_wet(nocta_unit* self) {
 delay_data* data = self->data;
 return data->wet;
}

canonical_original_code:
int get_wet(struct nocta_unit *self) {
 struct delay_data *data = self->data;
 return data->wet;
}


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

result = *(_QWORD *)(a1 + 16);
*(_BYTE *)(result + 1) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
*(_BYTE *)(result + 1) = a2;
return result;
}

original_code:
void set_wet(nocta_unit* self, int wet) {
 delay_data* data = self->data;
 data->wet = wet;
}

canonical_original_code:
void set_wet(struct nocta_unit *self, int wet) {
 struct delay_data *data = self->data;
 data->wet = wet;
}

variable_types: wet int


decompiled_code:
__int64 __fastcall get_feedback(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 16) + 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 16) + 2LL);
}

original_code:
int get_feedback(nocta_unit* self) {
 delay_data* data = self->data;
 return data->feedback;
}

canonical_original_code:
int get_feedback(struct nocta_unit *self) {
 struct delay_data *data = self->data;
 return data->feedback;
}


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

result = *(_QWORD *)(a1 + 16);
*(_BYTE *)(result + 2) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
*(_BYTE *)(result + 2) = a2;
return result;
}

original_code:
void set_feedback(nocta_unit* self, int feedback) {
 delay_data* data = self->data;
 data->feedback = feedback;
}

canonical_original_code:
void set_feedback(struct nocta_unit *self, int feedback) {
 struct delay_data *data = self->data;
 data->feedback = feedback;
}

variable_types: feedback int


decompiled_code:
__int64 __fastcall get_time(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(*(_QWORD *)(a1 + 16) + 4LL);
}

original_code:
int get_time(nocta_unit* self) {
 delay_data* data = self->data;
 return data->delay_time;
}

canonical_original_code:
int get_time(struct nocta_unit *self) {
 struct delay_data *data = self->data;
 return data->delay_time;
}


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

result = *(_QWORD *)(a1 + 16);
if ( a2 > 1023 )
a2 = 1023;
if ( a2 <= 0 )
a2 = 1;
*(_DWORD *)(result + 4) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 16);
if ( a2 > 1023 )
a2 = 1023;
if ( a2 <= 0 )
a2 = 1;
*(_DWORD *)(result + 4) = a2;
return result;
}

original_code:
void set_time(nocta_unit* self, int t) {
 delay_data* data = self->data;
 data->delay_time = ((t)<(1)?(1):((t)>(4*256 - 1)?(4*256 - 1):(t)));
}

canonical_original_code:
void set_time(struct nocta_unit *self, int t) {
 struct delay_data *data = self->data;
 data->delay_time = ((t)<(1)?(1):((t)>(4*256 - 1)?(4*256 - 1):(t)));
}

variable_types: t int


original_code:
static void delay_free(nocta_unit* self) {
 delay_data* data = self->data;
 free(data->l.pre_samples);
 free(data->l.samples);
 free(data->r.pre_samples);
 free(data->r.samples);
}

canonical_original_code:
static void delay_free(struct nocta_unit *self) {
 struct delay_data *data = self->data;
 free(data->l.pre_samples);
 free(data->l.samples);
 free(data->r.pre_samples);
 free(data->r.samples);
}


original_code:
nocta_unit* nocta_delay(nocta_context* context) {
 int buffer_size = 2 * 4 * context->sample_rate;
 int alloc_size = sizeof(int16_t) * buffer_size;
 delay_data* data = ialloc_impl(sizeof(delay_data), &(delay_data){ .dry = 255, .wet = 127, .feedback = 100, .l = (delay_buffer){ malloc(alloc_size), malloc(alloc_size), buffer_size }, .r = (delay_buffer){ malloc(alloc_size), malloc(alloc_size), buffer_size }, .sample_rate = context->sample_rate });
 nocta_unit* self = nocta_create_impl((nocta_unit) { context, .name = "delay", .data = data, .process_l = delay_l, .process_r = delay_r, .free = delay_free, .params = delay_params, .num_params = NOCTA_DELAY_NUM_PARAMS });
 set_time(self, 127);
 return self;
}

canonical_original_code:
struct nocta_unit *nocta_delay(struct nocta_context *context) {
 int buffer_size = 2 * 4 * context->sample_rate;
 int alloc_size = sizeof(int16_t) * buffer_size;
 struct delay_data *data = ialloc_impl(sizeof(delay_data), &(delay_data){ .dry = 255, .wet = 127, .feedback = 100, .l = (delay_buffer){ malloc(alloc_size), malloc(alloc_size), buffer_size }, .r = (delay_buffer){ malloc(alloc_size), malloc(alloc_size), buffer_size }, .sample_rate = context->sample_rate });
 struct nocta_unit *self = nocta_create_impl((nocta_unit) { context, .name = "delay", .data = data, .process_l = delay_l, .process_r = delay_r, .free = delay_free, .params = delay_params, .num_params = NOCTA_DELAY_NUM_PARAMS });
 set_time(self, 127);
 return self;
}


clip

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

result = 0x7FFFLL;
if ( a1 <= 0x7FFF )
result = (unsigned int)a1;
if ( (int)result < -32768 )
result = 4294934528LL;
return result;
}

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

result = 0x7FFFLL;
if ( a1 <= 0x7FFF )
result = (unsigned int)a1;
if ( (int)result < -32768 )
result = 4294934528LL;
return result;
}


decompiled_code:
void __fastcall nocta_free(void *ptr)
{
void (*v2)(void); // rax
void *v3; // rdi

v2 = (void (*)(void))*((_QWORD *)ptr + 5);
if ( v2 )
v2();
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}

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

v2 = (void (*)(void))*((_QWORD *)ptr + 5);
if ( v2 )
v2();
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}

original_code:
void nocta_free(nocta_unit* unit) {
 if (unit->free) unit->free(unit);
 if (unit->data) free(unit->data);
 free(unit);
}

canonical_original_code:
void nocta_free(struct nocta_unit *unit) {
 if (unit->free) unit->free(unit);
 if (unit->data) free(unit->data);
 free(unit);
}


original_code:
void nocta_process_buffer(nocta_unit* unit, int16_t* buffer, size_t length) {
 for (int i=0; i<length/2; i++) {
  *buffer = clip(unit->process_l(unit, *buffer));
  buffer++;
  *buffer = clip(unit->process_r(unit, *buffer));
  buffer++;
 }
}

canonical_original_code:
void nocta_process_buffer(struct nocta_unit *unit, short *buffer, unsigned long length) {
 for (int i = 0; i<length/2; i++) {
  *buffer = clip(unit->process_l(unit, *buffer));
  buffer++;
  *buffer = clip(unit->process_r(unit, *buffer));
  buffer++;
 }
}

variable_types:
buffer
short *

variable_types:
length
unsigned long


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

result = 0LL;
if ( *(_DWORD *)(a1 + 56) > a2 )
result = (*(__int64 (**)(void))(*(_QWORD *)(a1 + 48) + 32LL * a2 + 16))();
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 56) > a2 )
result = (*(__int64 (**)(void))(*(_QWORD *)(a1 + 48) + 32LL * a2 + 16))();
return result;
}

original_code:
int nocta_get(nocta_unit* unit, int param_id) {
 if (param_id >= unit->num_params)
  return 0;
 nocta_param* param = &unit->params[param_id];
 return param->get(unit);
}

canonical_original_code:
int nocta_get(struct nocta_unit *unit, int param_id) {
 if (param_id >= unit->num_params)
  return 0;
 struct nocta_param *param = &unit->params[param_id];
 return param->get(unit);
}

variable_types: struct nocta_param { char *name; int min; int (*get)(struct nocta_unit { struct nocta_context { int sample_rate; } *context; char *name; void *data; int (*process_l)(struct nocta_unit *self, int l); int (*process_r)(struct nocta_unit *self, int r); void (*free)(struct nocta_unit *self); struct nocta_param *params; int num_params; } *unit); void (*set)(struct nocta_unit *unit, int val); } *