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


repo: gcali/minesweeper

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: i int

variable_types: done int

variable_types: j int

return_type: int


main

canonical_name: main

repo: gchelfi/JeuxChiffres

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

closest = new_tree(0xFFFFFFFFLL, 102LL, envp);
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 = acquire_from_file(argv[1]);
else
numbers_0 = acquire_from_command((unsigned int)argc, argv);
v4 = transform(numbers_0);
cover_isra_0(v4, (unsigned int)p);
printf("Target: %d\n", (unsigned int)N);
printf("Available numbers: ");
if ( p )
{
v5 = 0;
do
{
v6 = v5++;
printf("%d ", *(unsigned int *)(numbers_0 + 4 * v6));
}
while ( p > v5 );
}
puts("\nResult:");
pretty_print(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
__int64 v4; // rax
unsigned int v5; // ebx
__int64 v6; // rdx

closest = new_tree(0xFFFFFFFFLL, 102LL, envp);
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 = func11(argv[1]);
else
numbers_0 = acquire_from_command((unsigned int)argc, argv);
v4 = func10(numbers_0);
func15(v4, (unsigned int)p);
printf("Target: %d\n", (unsigned int)N);
printf("Available numbers: ");
if ( p )
{
v5 = 0;
do
{
v6 = v5++;
printf("%d ", *(unsigned int *)(numbers_0 + 4 * v6));
}
while ( p > v5 );
}
puts("\nResult:");
func12(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; } **


eval

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 )
return 0LL;
if ( v3 <= v4 )
result = (unsigned int)(v4 / v3);
else
result = (unsigned int)(v3 / v4);
}
else
{
if ( a3 != 42 )
{
if ( a3 == 43 )
return (unsigned int)(v3 + v4);
return 0LL;
}
result = (unsigned int)(v4 * v3);
}
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 )
return 0LL;
if ( v3 <= v4 )
result = (unsigned int)(v4 / v3);
else
result = (unsigned int)(v3 / v4);
}
else
{
if ( a3 != 42 )
{
if ( a3 == 43 )
return (unsigned int)(v3 + v4);
return 0LL;
}
result = (unsigned int)(v4 * v3);
}
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)
{
unsigned int *v1; // rbx
char v2; // al
_DWORD *v3; // rdi

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

canonical_decompiled_code:
void __fastcall func12(unsigned int *a1)
{
unsigned int *v1; // rbx
char v2; // al
_DWORD *v3; // rdi

if ( a1 )
{
v1 = a1;
while ( 1 )
{
v2 = *((_BYTE *)v1 + 4);
if ( v2 == 111 )
{
printf("%d", *v1);
return;
}
if ( v2 != 42 )
break;
func12(*((_QWORD *)v1 + 1));
printf(" %c ", (unsigned int)*((char *)v1 + 4));
v1 = (unsigned int *)*((_QWORD *)v1 + 2);
if ( !v1 )
return;
}
putchar(40);
v3 = (_DWORD *)*((_QWORD *)v1 + 2);
if ( **((_DWORD **)v1 + 1) > *v3 )
{
func12(*((_QWORD *)v1 + 1));
printf(" %c ", (unsigned int)*((char *)v1 + 4));
func12(*((_QWORD *)v1 + 2));
}
else
{
func12(v3);
printf(" %c ", (unsigned int)*((char *)v1 + 4));
func12(*((_QWORD *)v1 + 1));
}
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

repo: gchiesa/php-mfcobol

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

if ( argc != 2 )
{
printf("Usage: %s <LOGFILE>\n", *argv);
exit(1);
}
v3 = strcpy(v5, argv[1]);
if ( (int)islogopen(v3) < 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 *v4; // rdi

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

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

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

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; // rbx
__int64 v5; // r13
int v6; // er14
__int64 v7; // rcx
__int64 result; // rax
int v9; // er14
__int64 v10; // rcx
int v11; // 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();
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);
if ( *(_DWORD *)(a2 + 40) > v9 )
{
v10 = *(unsigned int *)(a2 + 44);
v11 = 12;
}
else
{
*(_DWORD *)(a2 + 44) = 0;
v10 = 0LL;
v11 = 0;
}
draw_textbox(
*(_QWORD *)(a2 + 48),
a2 + 40,
1LL,
v10,
(*(_DWORD *)(a2 + 36) & 2) == 0,
8LL,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
(unsigned int)(*(_DWORD *)(a2 + 16) - v11),
*(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; // rbx
__int64 v5; // r13
int v6; // er14
__int64 v7; // rcx
__int64 result; // rax
int v9; // er14
__int64 v10; // rcx
int v11; // 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();
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);
if ( *(_DWORD *)(a2 + 40) > v9 )
{
v10 = *(unsigned int *)(a2 + 44);
v11 = 12;
}
else
{
*(_DWORD *)(a2 + 44) = 0;
v10 = 0LL;
v11 = 0;
}
draw_textbox(
*(_QWORD *)(a2 + 48),
a2 + 40,
1LL,
v10,
(*(_DWORD *)(a2 + 36) & 2) == 0,
8LL,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
(unsigned int)(*(_DWORD *)(a2 + 16) - v11),
*(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);
}


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

decompiled_code:
__int64 __fastcall nv_split(char *a1, char **a2)
{
char *v2; // rax
char *v3; // rax
char *v5; // rax
char *v6; // rax

*a2 = 0LL;
a2[1] = 0LL;
a2[2] = 0LL;
v2 = strtok(a1, " ");
if ( !v2 || *v2 == 35 )
return 0LL;
*a2 = v2;
v3 = strtok(0LL, " ");
if ( v3 )
{
if ( *v3 != 61 || v3[1] )
return 2LL;
v5 = strtok(0LL, " ");
if ( v5 )
{
a2[1] = v5;
v6 = strtok(0LL, " ");
if ( v6 )
{
a2[2] = v6;
return strtok(0LL, " ") != 0LL;
}
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char **a2)
{
char *v2; // rax
char *v3; // rax
char *v5; // rax
char *v6; // rax

*a2 = 0LL;
a2[1] = 0LL;
a2[2] = 0LL;
v2 = strtok(a1, " ");
if ( !v2 || *v2 == 35 )
return 0LL;
*a2 = v2;
v3 = strtok(0LL, " ");
if ( v3 )
{
if ( *v3 != 61 || v3[1] )
return 2LL;
v5 = strtok(0LL, " ");
if ( v5 )
{
a2[1] = v5;
v6 = strtok(0LL, " ");
if ( v6 )
{
a2[2] = v6;
return strtok(0LL, " ") != 0LL;
}
return 0LL;
}
}
return 1LL;
}

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; // rdi
int v3; // ebp
char **v4; // rbx

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

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

v2 = "remote_server";
v3 = 0;
v4 = &keywords;
do
{
if ( !strcasecmp(v2, s2) )
break;
v2 = v4[3];
v4 += 3;
++v3;
}
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 server_parser(__int64 a1, __int64 a2, char **a3)
{
const char *v3; // rdi
__int64 result; // rax

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

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

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

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

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 port_parser(__int64 a1, unsigned int a2, __int64 a3)
{
return parse_uint_constprop_0(a1, a2, (int *)(a3 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
return func4(a1, a2, (int *)(a3 + 8));
}

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

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


decompiled_code:
__int64 __fastcall clear_config(_QWORD *a1)
{
__int64 result; // rax

result = 0xA800000202LL;
*a1 = 0LL;
a1[1] = 0xA800000202LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 result; // rax

result = 0xA800000202LL;
*a1 = 0LL;
a1[1] = 0xA800000202LL;
return result;
}

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; // r12

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; // r12

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:
// attributes: thunk
int print_code(const char *s)
{
return puts(s);
}

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

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:
// attributes: thunk
int __fastcall print_node(const char *s)
{
return print_code(s);
}

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

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 )
return list_foreach(a1, print_node);
puts("print_tac called on null");
return list_foreach(0LL, print_node);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
if ( a1 )
return list_foreach(a1, print_node);
puts("print_tac called on null");
return list_foreach(0LL, 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
__int64 v2; // rdx

result = a1;
do
{
v2 = result;
result = *(_QWORD *)(result + 8);
}
while ( result != v2 );
return result;
}

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

result = a1;
do
{
v2 = result;
result = *(_QWORD *)(result + 8);
}
while ( result != v2 );
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; // rax
const char **v3; // rcx

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

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

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

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 *v2; // rbx

if ( a2 )
{
v2 = a2;
do
{
list_append(a1, *v2);
v2 = (__int64 *)v2[1];
}
while ( v2 );
}
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)
{
return svfilter_run(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 16) + 48LL);
}

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)
{
return svfilter_run(*(_QWORD *)(a1 + 16), *(_QWORD *)(a1 + 16) + 24LL);
}

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 get_dry(__int64 a1)
{
return **(unsigned __int8 **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func0(__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;
}

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 get_wet(__int64 a1)
{
return *(unsigned __int8 *)(*(_QWORD *)(a1 + 16) + 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__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;
}

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


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 func2(__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 func3(__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 func4(__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 func5(__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 func6(__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:
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);
}


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


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 (*v1)(void); // rax
void *v3; // rdi

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

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

v1 = (void (*)(void))*((_QWORD *)ptr + 5);
if ( v1 )
v1();
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

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

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

if ( *(_DWORD *)(a1 + 56) <= a2 )
result = 0LL;
else
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); } *


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

if ( *(_DWORD *)(a1 + 56) > a2 )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(a1 + 48) + 32LL * a2 + 24))(a1, a3);
return result;
}

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

if ( *(_DWORD *)(a1 + 56) > a2 )
result = (*(__int64 (__fastcall **)(__int64, _QWORD))(*(_QWORD *)(a1 + 48) + 32LL * a2 + 24))(a1, a3);
return result;
}

original_code:
void nocta_set(nocta_unit* unit, int param_id, int val) {
 if (param_id >= unit->num_params)
  return;
 nocta_param* param = &unit->params[param_id];
 param->set(unit, val);
}

canonical_original_code:
void nocta_set(struct nocta_unit *unit, int param_id, int val) {
 if (param_id >= unit->num_params)
  return;
 struct nocta_param *param = &unit->params[param_id];
 param->set(unit, val);
}

variable_types: val int


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

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

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

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

original_code:
nocta_param* nocta_get_param(nocta_unit* unit, int param_id) {
 return param_id < unit->num_params ? &unit->params[param_id] : ((void *)0);
}

canonical_original_code:
struct nocta_param *nocta_get_param(struct nocta_unit *unit, int param_id) {
 return param_id < unit->num_params ? &unit->params[param_id] : ((void *)0);
}

variable_types:
unit
struct nocta_unit *

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


decompiled_code:
__int64 __fastcall gainer_process_l(__int64 a1, int a2)
{
unsigned __int8 *v2; // rax
int v3; // ecx

v2 = *(unsigned __int8 **)(a1 + 16);
v3 = 255;
if ( (char)v2[1] > 0 )
v3 = 255 - 2 * (char)v2[1];
return (unsigned int)((a2 * ((v3 * *v2) >> 8)) >> 7);
}

original_code:
static int gainer_process_l(nocta_unit* self, int in) {
 gainer_data* data = self->data;
 int amp = 255;
 if (data->pan > 0) amp -= 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

canonical_original_code:
static int gainer_process_l(struct nocta_unit *self, int in) {
 struct gainer_data *data = self->data;
 int amp = 255;
 if (data->pan > 0) amp -= 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

variable_types: in int

variable_types: struct gainer_data { unsigned char vol; char pan; } *

variable_types: amp int


original_code:
static int gainer_process_r(nocta_unit* self, int in) {
 gainer_data* data = self->data;
 int amp = 255;
 if (data->pan < 0) amp += 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

canonical_original_code:
static int gainer_process_r(struct nocta_unit *self, int in) {
 struct gainer_data *data = self->data;
 int amp = 255;
 if (data->pan < 0) amp += 2 * data->pan;
 amp = amp * data->vol >> 8;
 return in * amp >> 7;
}

user_defined_types: struct gainer_data { unsigned char vol; char pan; }


decompiled_code:
__int64 __fastcall get_pan(__int64 a1)
{
return (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return (unsigned int)*(char *)(*(_QWORD *)(a1 + 16) + 1LL);
}

original_code:
static int get_pan(nocta_unit* self) {
 gainer_data* data = self->data;
 return data->pan;
}

canonical_original_code:
static int get_pan(struct nocta_unit *self) {
 struct gainer_data *data = self->data;
 return data->pan;
}


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

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

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

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

original_code:
static void set_pan(nocta_unit* self, int pan) {
 gainer_data* data = self->data;
 data->pan = pan;
}

canonical_original_code:
static void set_pan(struct nocta_unit *self, int pan) {
 struct gainer_data *data = self->data;
 data->pan = pan;
}

variable_types: pan int


original_code:
nocta_unit* nocta_gainer(nocta_context* context) {
 return nocta_create_impl((nocta_unit) { .context = context, .name = "gainer", .data = ialloc_impl(sizeof(gainer_data), &(gainer_data){ .vol = 128, .pan = 0 }), .process_l = gainer_process_l, .process_r = gainer_process_r, .params = gainer_params, .num_params = NOCTA_GAINER_NUM_PARAMS });
}

canonical_original_code:
struct nocta_unit *nocta_gainer(struct nocta_context *context) {
 return nocta_create_impl((struct nocta_unit) { .context = context, .name = "gainer", .data = ialloc_impl(sizeof(gainer_data), &(struct gainer_data){ .vol = 128, .pan = 0 }), .process_l = gainer_process_l, .process_r = gainer_process_r, .params = gainer_params, .num_params = NOCTA_GAINER_NUM_PARAMS });
}


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


decompiled_code:
__int64 __fastcall fix_div(int a1, int a2)
{
return (unsigned int)((a1 << 13) / a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return (unsigned int)((a1 << 13) / a2);
}

original_code:
inline static int32_t fix_div(int32_t a, int32_t b) {
 return (a << 13) / b;
}

canonical_original_code:
inline static int fix_div(int a, int b) {
 return (a << 13) / b;
}


original_code:
static int bqfilter_run(filter_data* data, filter_state* state, int input) {
 int output = fix_mul(data->b0, input);
 output += fix_mul(data->b1, state->in1);
 output += fix_mul(data->b2, state->in2);
 output -= fix_mul(data->a1, state->out1);
 output -= fix_mul(data->a2, state->out2);
 state->in2 = state->in1;
 state->in1 = input;
 state->out2 = state->out1;
 state->out1 = output;
 return output;
}

canonical_original_code:
static int bqfilter_run(struct filter_data *data, struct filter_state *state, int input) {
 int output = fix_mul(data->b0, input);
 output += fix_mul(data->b1, state->in1);
 output += fix_mul(data->b2, state->in2);
 output -= fix_mul(data->a1, state->out1);
 output -= fix_mul(data->a2, state->out2);
 state->in2 = state->in1;
 state->in1 = input;
 state->out2 = state->out1;
 state->out1 = output;
 return output;
}

variable_types: struct filter_data { unsigned char vol; int mode; int freq; int amp; unsigned char res; int a0; int b0; struct filter_state { int in1; int out1; } l[2]; } *

variable_types:
state
struct filter_state *

variable_types: input int

variable_types: output int

user_defined_types: struct filter_data { unsigned char vol; int mode; int freq; int amp; unsigned char res; int a0; int b0; struct filter_state l[2]; }


decompiled_code:
__int64 __fastcall bqfilter_r(__int64 a1, int a2)
{
unsigned __int8 *v2; // rbx
int v3; // eax

v2 = *(unsigned __int8 **)(a1 + 16);
v3 = bqfilter_run((__int64)v2, (__int64)(v2 + 76), (a2 * *((_DWORD *)v2 + 3)) >> 8);
return (unsigned int)((int)(bqfilter_run((__int64)v2, (__int64)(v2 + 92), v3) * *v2) >> 8);
}

original_code:
static int bqfilter_r(nocta_unit* self, int x) {
 filter_data* data = self->data;
 x = x*data->amp >> 8;
 for (int i=0; i<2; i++) {
  x = bqfilter_run(data, &data->r[i], x);
 }
 return x*data->vol >> 8;
}

canonical_original_code:
static int bqfilter_r(struct nocta_unit *self, int x) {
 struct filter_data *data = self->data;
 x = x*data->amp >> 8;
 for (int i = 0; i<2; i++) {
  x = bqfilter_run(data, &data->r[i], x);
 }
 return x*data->vol >> 8;
}

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

variable_types: i int

user_defined_types: struct filter_state { int in1; int out1; }


decompiled_code:
__int64 __fastcall bqfilter_l(__int64 a1, int a2)
{
unsigned __int8 *v2; // rbx
int v3; // eax

v2 = *(unsigned __int8 **)(a1 + 16);
v3 = bqfilter_run((__int64)v2, (__int64)(v2 + 44), (a2 * *((_DWORD *)v2 + 3)) >> 8);
return (unsigned int)((int)(bqfilter_run((__int64)v2, (__int64)(v2 + 60), v3) * *v2) >> 8);
}

original_code:
static int bqfilter_l(nocta_unit* self, int x) {
 filter_data* data = self->data;
 x = x*data->amp >> 8;
 for (int i=0; i<2; i++) {
  x = bqfilter_run(data, &data->l[i], x);
 }
 return x*data->vol >> 8;
}

canonical_original_code:
static int bqfilter_l(struct nocta_unit *self, int x) {
 struct filter_data *data = self->data;
 x = x*data->amp >> 8;
 for (int i = 0; i<2; i++) {
  x = bqfilter_run(data, &data->l[i], x);
 }
 return x*data->vol >> 8;
}


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

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

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

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

variable_types: y double


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


decompiled_code:
__int64 nocta_bqfilter()
{
__int64 v0; // r12
_BYTE v2[104]; // [rsp+40h] [rbp-78h] BYREF
int v3; // [rsp+A8h] [rbp-10h]

memset(v2, 0, sizeof(v2));
v2[0] = -1;
*(_DWORD *)&v2[8] = 22050;
v3 = 0;
ialloc_impl_constprop_0((const __m128i *)v2);
v0 = nocta_create_impl(0.0);
set_mode(v0, 0);
return v0;
}

original_code:
nocta_unit* nocta_bqfilter(nocta_context* context) {
 nocta_unit* self = nocta_create_impl((nocta_unit) { .context = context, .name = "bqfilter", .data = ialloc_impl(sizeof(filter_data), &(filter_data){ .vol = 255, .freq = 22050, .res = 0 }), .process_l = bqfilter_l, .process_r = bqfilter_r, .params = bqfilter_params, .num_params = NOCTA_FILTER_NUM_PARAMS });
 set_mode(self, NOCTA_FILTER_MODE_LOWPASS);
 return self;
}

canonical_original_code:
struct nocta_unit *nocta_bqfilter(struct nocta_context *context) {
 struct nocta_unit *self = nocta_create_impl((nocta_unit) { .context = context, .name = "bqfilter", .data = ialloc_impl(sizeof(filter_data), &(filter_data){ .vol = 255, .freq = 22050, .res = 0 }), .process_l = bqfilter_l, .process_r = bqfilter_r, .params = bqfilter_params, .num_params = NOCTA_FILTER_NUM_PARAMS });
 set_mode(self, NOCTA_FILTER_MODE_LOWPASS);
 return self;
}

variable_types:
context
struct nocta_context *


main

repo: geekofhearts/lang

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
__int64 v4; // rax
__int64 v5; // rdi
int result; // eax

setup_error_handling(argc, argv, envp);
if ( argc <= 1 )
{
print_version_info(*argv);
result = prompt();
}
else
{
v3 = (unsigned int *)malloc(4uLL);
v4 = parseopts((unsigned int)argc, argv, v3);
v5 = *v3;
if ( (_DWORD)v5 )
result = script(v5, v4);
else
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int *v3; // rbx
__int64 v4; // rax
__int64 v5; // rdi
int result; // eax

func13(argc, argv, envp);
if ( argc <= 1 )
{
func10(*argv);
result = func14();
}
else
{
v3 = (unsigned int *)malloc(4uLL);
v4 = func12((unsigned int)argc, argv, v3);
v5 = *v3;
if ( (_DWORD)v5 )
result = func15(v5, v4);
else
result = 0;
}
return result;
}

original_code:
int main(int argc, char** argv) {
  setup_error_handling();
  if (argc > 1) {
    int* script_argc = (int*)malloc(sizeof(int));
    char** script_and_args = parseopts(argc, argv, script_argc);
    if (*(script_argc)) {
      return script(*(script_argc), script_and_args);
    }
    return 0;
  } else {
    print_version_info(argv[0]);
    return prompt();
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  setup_error_handling();
  if (argc > 1) {
    int *script_argc = (int*)malloc(sizeof(int));
    char **script_and_args = parseopts(argc, argv, script_argc);
    if (*(script_argc)) {
      return script(*(script_argc), script_and_args);
    }
    return 0;
  } else {
    print_version_info(argv[0]);
    return prompt();
  }
}

variable_types: argc int

variable_types:
argv
char **


original_code:
void context_destroy(void* the_context) {
  context_t* typed_context = (context_t*)the_context;
  variable_t* var = (variable_t*)typed_context->local_variables[0];
  int i;
  for (i = 0; var != ((void *)0); var = (variable_t*)(typed_context->local_variables[++i])) {
    var->destructor((void*)var);
  }
  free(typed_context->local_variables);
}

canonical_original_code:
void context_destroy(void *the_context) {
  struct context_t *typed_context = (context_t*)the_context;
  struct variable_t *var = (variable_t*)typed_context->local_variables[0];
  int i;
  for (i = 0; var != ((void *)0); var = (struct variable_t *)(typed_context->local_variables[++i])) {
    var->destructor((void *)var);
  }
  free(typed_context->local_variables);
}

variable_types: struct context_t { void **local_variables; int thread_id; void **global_variables; } *

variable_types: struct variable_t { char *name; void *value; void (*destructor)(void *); } *


decompiled_code:
void __fastcall __noreturn raise_error(const char *a1)
{
printf("ERROR: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(const char *a1)
{
printf("ERROR: %s\n", a1);
exit(1);
}

original_code:
void raise_error(char* message) {
  printf("ERROR: %s\n", message);
  exit(1);
}

canonical_original_code:
void raise_error(char *message) {
  printf("ERROR: %s\n", message);
  exit(1);
}

variable_types:
message
char *


decompiled_code:
void __noreturn segfault_handler()
{
puts("ERROR: caught a segmentation fault: most likely the system refused to allocate the RAM you or lang requested.");
puts("exiting now.");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
puts("ERROR: caught a segmentation fault: most likely the system refused to allocate the RAM you or lang requested.");
puts("exiting now.");
exit(1);
}

original_code:
void segfault_handler(int signal) {
  printf("ERROR: caught a segmentation fault: most likely the system refused to allocate the RAM you or lang requested.\n");
  printf("exiting now.\n");
  exit(1);
}

variable_types: signal int


decompiled_code:
int __fastcall print_version_info(const char *a1)
{
return printf("%s v%i.%i\n", a1, 0LL, 1LL);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
return printf("%s v%i.%i\n", a1, 0LL, 1LL);
}

original_code:
void print_version_info(char* name) {
  printf("%s v%i.%i\n", name, 0, 1);
}

canonical_original_code:
void print_version_info(char *name) {
  printf("%s v%i.%i\n", name, 0, 1);
}

variable_types:
name
char *


decompiled_code:
int setup_error_handling()
{
struct sigaction *v0; // rax
const struct sigaction *v1; // rbp

v0 = (struct sigaction *)malloc(0x98uLL);
v0->sa_handler = (__sighandler_t)segfault_handler;
v1 = v0;
sigemptyset(&v0->sa_mask);
v1->sa_flags = 0;
return sigaction(11, v1, 0LL);
}

canonical_decompiled_code:
int func13()
{
struct sigaction *v0; // rax
const struct sigaction *v1; // rbp

v0 = (struct sigaction *)malloc(0x98uLL);
v0->sa_handler = (__sighandler_t)segfault_handler;
v1 = v0;
sigemptyset(&v0->sa_mask);
v1->sa_flags = 0;
return sigaction(11, v1, 0LL);
}

original_code:
void setup_error_handling(void) {
  struct sigaction* action = (struct sigaction*)malloc(sizeof(struct sigaction));
  action->__sigaction_handler.sa_handler = &segfault_handler;
  sigemptyset(&(action->sa_mask));
  action->sa_flags = 0;
  sigaction(11, action, ((void *)0));
}

canonical_original_code:
void setup_error_handling() {
  struct sigaction *action = (struct sigaction*)malloc(sizeof(struct sigaction));
  action->__sigaction_handler.sa_handler = &segfault_handler;
  sigemptyset(&(action->sa_mask));
  action->sa_flags = 0;
  sigaction(11, action, ((void *)0));
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); } *

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }