ParseLongIntXML

original_code:
long int ParseLongIntXML(char *buffer,unsigned long linenum)
{
 char numberbuffer[11]={0};
 unsigned long index=0;
 unsigned long index2=0;
 char *tempstr=((void *)0);
 long num;
 assert_wrapper(buffer != ((void *)0));
 while(buffer[index] != '\0')
 {
  if(buffer[index] == '<')
   break;
  if(index2 >= 10)
   break;
  numberbuffer[index2++]=buffer[index++];
 }
 numberbuffer[index2]='\0';
 tempstr=RemoveLeadingZeroes(numberbuffer);
 if(tempstr[0] == '0')
 {
  num = 0;
 }
 else
 {
  num = atol(tempstr);
  if(!num)
  {
   printf("Error converting numerical string to numerical value.\nError occurs in line %lu of input file\nAborting\n",linenum);
   exit_wrapper(2);
  }
 }
 free(tempstr);
 return num;
}

canonical_original_code:
long ParseLongIntXML(char *buffer, unsigned long linenum)
{
 char numberbuffer[11] = {0};
 unsigned long index = 0;
 unsigned long index2 = 0;
 char *tempstr = ((void *)0);
 long num;
 assert_wrapper(buffer != ((void *)0));
 while(buffer[index] != '\0')
 {
  if(buffer[index] == '<')
   break;
  if(index2 >= 10)
   break;
  numberbuffer[index2++]=buffer[index++];
 }
 numberbuffer[index2]='\0';
 tempstr=RemoveLeadingZeroes(numberbuffer);
 if(tempstr[0] == '0')
 {
  num = 0;
 }
 else
 {
  num = atol(tempstr);
  if(!num)
  {
   printf("Error converting numerical string to numerical value.\nError occurs in line %lu of input file\nAborting\n",linenum);
   exit_wrapper(2);
  }
 }
 free(tempstr);
 return num;
}

variable_types:
buffer
char *

variable_types:
linenum
unsigned long

variable_types:
numberbuffer
char [11]

variable_types:
index
unsigned long

variable_types:
tempstr
char *

variable_types: num long

return_type: long


repo: cincodenada/editor-on-fire

original_code:
double notefunc_note_to_freq(char* note)
{
 char notename;
 char octavestr[10];
 int octavenum;
 char accidental = 0;
 int adj = 0;
 size_t notenum = 0, numnotes = strlen(notelist);
 notename = note[0];
 if(strlen(note) == 2)
 {
  strncpy(octavestr, note + 1, sizeof(octavestr) - 1);
  accidental = 0;
 }
 else if(strlen(note) == 3)
 {
  strncpy(octavestr, note + 2, sizeof(octavestr) - 1);
  accidental = note[1];
 }
 else
 {
  return 440;
 }
 octavestr[9] = '\0';
 octavenum = atoi(octavestr);
 if(notename > 90)
 {
  notename -= 32;
 }
 for(notenum=0;notenum < numnotes;notenum++)
 {
  if(notelist[notenum] == notename)
   break;
 }
 if(notenum == numnotes)
 {
  return 440;
 }
 if(accidental)
 {
  if(accidental == '#')
  {
   adj = 1;
  }
  else if(accidental == 'b')
  {
   adj = -1;
  }
  notenum = (notenum + adj) % numnotes;
 }
 return round(16.3515978312874 * pow(2,(double)octavenum+(notenum/12.0)) *100)/100;
}

canonical_original_code:
double notefunc_note_to_freq(char *note)
{
 char notename;
 char octavestr[10];
 int octavenum;
 char accidental = 0;
 int adj = 0;
 unsigned long notenum = 0; unsigned long numnotes = strlen(notelist);
 notename = note[0];
 if(strlen(note) == 2)
 {
  strncpy(octavestr, note + 1, sizeof(octavestr) - 1);
  accidental = 0;
 }
 else if(strlen(note) == 3)
 {
  strncpy(octavestr, note + 2, sizeof(octavestr) - 1);
  accidental = note[1];
 }
 else
 {
  return 440;
 }
 octavestr[9] = '\0';
 octavenum = atoi(octavestr);
 if(notename > 90)
 {
  notename -= 32;
 }
 for(notenum=0;notenum < numnotes;notenum++)
 {
  if(notelist[notenum] == notename)
   break;
 }
 if(notenum == numnotes)
 {
  return 440;
 }
 if(accidental)
 {
  if(accidental == '#')
  {
   adj = 1;
  }
  else if(accidental == 'b')
  {
   adj = -1;
  }
  notenum = (notenum + adj) % numnotes;
 }
 return round(16.3515978312874 * pow(2,(double)octavenum+(notenum/12.0)) *100)/100;
}

variable_types:
note
char *

variable_types: notename char

variable_types:
octavestr
char [10]

variable_types: octavenum int

variable_types: accidental char

variable_types: adj int

variable_types:
notenum
unsigned long

variable_types:
numnotes
unsigned long

return_type: double


decompiled_code:
char *__fastcall notefunc_freq_to_note(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 v3; // r8
double v4; // xmm7_8

v1 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(_log_finite(a1 * 0.06115610292754293) * 1.442695040888963) & LC4) * 100.0;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC4) < 4.503599627370496e15 )
*(_QWORD *)&v1 = COERCE_UNSIGNED_INT64((double)(int)(COERCE_DOUBLE(*(_QWORD *)&v1 & LC4) + 0.4999999999999999)) | ~LC4 & *(_QWORD *)&v1;
v2 = v1 * 0.01;
v3 = (unsigned int)(int)v2;
v4 = (double)(int)v3;
if ( (double)(int)v3 > v2 )
{
v3 = (unsigned int)(v3 - 1);
v4 = (double)(int)v3;
}
snprintf(
returnval,
9uLL,
"%s%d",
(const char *)notenames
+ 3 * (int)(COERCE_DOUBLE(LC5 | LC11 & COERCE_UNSIGNED_INT64((v2 - v4) * 12.0)) + (v2 - v4) * 12.0),
v3);
return returnval;
}

canonical_decompiled_code:
char *__fastcall func1(double a1)
{
double v1; // xmm0_8
double v2; // xmm0_8
__int64 v3; // r8
double v4; // xmm7_8

v1 = COERCE_DOUBLE(COERCE_UNSIGNED_INT64(_log_finite(a1 * 0.06115610292754293) * 1.442695040888963) & LC4) * 100.0;
if ( COERCE_DOUBLE(*(_QWORD *)&v1 & LC4) < 4.503599627370496e15 )
*(_QWORD *)&v1 = COERCE_UNSIGNED_INT64((double)(int)(COERCE_DOUBLE(*(_QWORD *)&v1 & LC4) + 0.4999999999999999)) | ~LC4 & *(_QWORD *)&v1;
v2 = v1 * 0.01;
v3 = (unsigned int)(int)v2;
v4 = (double)(int)v3;
if ( (double)(int)v3 > v2 )
{
v3 = (unsigned int)(v3 - 1);
v4 = (double)(int)v3;
}
snprintf(
returnval,
9uLL,
"%s%d",
(const char *)notenames
+ 3 * (int)(COERCE_DOUBLE(LC5 | LC11 & COERCE_UNSIGNED_INT64((v2 - v4) * 12.0)) + (v2 - v4) * 12.0),
v3);
return returnval;
}

original_code:
char* notefunc_freq_to_note(double freq)
{
 double logof2 = log(2.0);
 double midval = round(fabs(log(freq/16.3515978312874)/logof2) *100)/100;
 int octavenum = floor(midval);
 int notenum = round(12.0*(midval - octavenum));
 (void) snprintf(returnval, sizeof(returnval) - 1, "%s%d", notenames+notenum*3, octavenum);
 return returnval;
}

canonical_original_code:
char *notefunc_freq_to_note(double freq)
{
 double logof2 = log(2.0);
 double midval = round(fabs(log(freq/16.3515978312874)/logof2) *100)/100;
 int octavenum = floor(midval);
 int notenum = round(12.0*(midval - octavenum));
 (void) snprintf(returnval, sizeof(returnval) - 1, "%s%d", notenames+notenum*3, octavenum);
 return returnval;
}

variable_types: freq double

variable_types: midval double

variable_types: notenum int

return_type: char *


decompiled_code:
__int64 __fastcall eof_verified_edit_proc(__int64 a1, __int64 a2, int a3)
{
int v4; // eax
_BYTE *v5; // rdx
int v6; // er9
char *v7; // rdx

if ( (_DWORD)a1 != 7 )
return d_agup_edit_proc(a1, a2, (unsigned int)a3);
v4 = a3 >> 8;
if ( a3 >> 8 == 63 || v4 == 77 || v4 == 82 || v4 == 83 || v4 == 84 || v4 == 85 || v4 == 59 || v4 == 67 )
return d_agup_edit_proc(7LL, a2, (unsigned int)a3);
v5 = *(_BYTE **)(a2 + 56);
if ( !v5 )
return d_agup_edit_proc(a1, a2, (unsigned int)a3);
v6 = (char)*v5;
if ( *v5 )
{
v7 = v5 + 1;
while ( v6 != (unsigned __int8)a3 )
{
v6 = *v7++;
if ( !(_BYTE)v6 )
return 16LL;
}
return d_agup_edit_proc(a1, a2, (unsigned int)a3);
}
return 16LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
int v4; // eax
_BYTE *v5; // rdx
int v6; // er9
char *v7; // rdx

if ( (_DWORD)a1 != 7 )
return d_agup_edit_proc(a1, a2, (unsigned int)a3);
v4 = a3 >> 8;
if ( a3 >> 8 == 63 || v4 == 77 || v4 == 82 || v4 == 83 || v4 == 84 || v4 == 85 || v4 == 59 || v4 == 67 )
return d_agup_edit_proc(7LL, a2, (unsigned int)a3);
v5 = *(_BYTE **)(a2 + 56);
if ( !v5 )
return d_agup_edit_proc(a1, a2, (unsigned int)a3);
v6 = (char)*v5;
if ( *v5 )
{
v7 = v5 + 1;
while ( v6 != (unsigned __int8)a3 )
{
v6 = *v7++;
if ( !(_BYTE)v6 )
return 16LL;
}
return d_agup_edit_proc(a1, a2, (unsigned int)a3);
}
return 16LL;
}

original_code:
int eof_verified_edit_proc(int msg, DIALOG *d, int c)
{
 int i;
 char * string = ((void *)0);
 int key_list[32] = {__allegro_KEY_BACKSPACE, __allegro_KEY_DEL, __allegro_KEY_LEFT, __allegro_KEY_RIGHT, __allegro_KEY_UP, __allegro_KEY_DOWN, __allegro_KEY_ESC, __allegro_KEY_ENTER};
 int match = 0;
 if(msg == 7)
 {
  for(i = 0; i < 8; i++)
  {
   if(c >> 8 == key_list[i])
   {
    return d_agup_edit_proc(msg, d, c);
   }
  }
  string = (char *)(d->dp2);
  if(string == ((void *)0))
   match = 1;
  else
  {
   for(i = 0; string[i] != '\0'; i++)
   {
    if(string[i] == (c & 0xff))
    {
     match = 1;
     break;
    }
   }
  }
  if(!match)
   return 16;
 }
 return d_agup_edit_proc(msg, d, c);
}

canonical_original_code:
int eof_verified_edit_proc(int msg, struct DIALOG *d, int c)
{
 int i;
 char *string = ((void *)0);
 int key_list[32] = {__allegro_KEY_BACKSPACE, __allegro_KEY_DEL, __allegro_KEY_LEFT, __allegro_KEY_RIGHT, __allegro_KEY_UP, __allegro_KEY_DOWN, __allegro_KEY_ESC, __allegro_KEY_ENTER};
 int match = 0;
 if(msg == 7)
 {
  for(i = 0; i < 8; i++)
  {
   if(c >> 8 == key_list[i])
   {
    return d_agup_edit_proc(msg, d, c);
   }
  }
  string = (char *)(d->dp2);
  if(string == ((void *)0))
   match = 1;
  else
  {
   for(i = 0; string[i] != '\0'; i++)
   {
    if(string[i] == (c & 0xff))
    {
     match = 1;
     break;
    }
   }
  }
  if(!match)
   return 16;
 }
 return d_agup_edit_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: i int

variable_types:
string
char *

variable_types: match int

return_type: int


decompiled_code:
void eof_prepare_main_menu()
{
bool v0; // zf

v0 = eof_song == 0LL;
*((_DWORD *)&eof_main_menu + 46) = 32;
if ( !v0 && eof_song_loaded )
{
*((_DWORD *)&eof_main_menu + 16) = 0;
*((_DWORD *)&eof_main_menu + 26) = 0;
*((_DWORD *)&eof_main_menu + 36) = 0;
*((_DWORD *)&eof_main_menu + 56) = 0;
if ( eof_count_selected_notes(0LL, 1LL) || eof_input_mode == 6 && eof_seek_hover_note >= 0 )
*((_DWORD *)&eof_main_menu + 46) = 0;
}
else
{
*((_DWORD *)&eof_main_menu + 16) = 32;
*((_DWORD *)&eof_main_menu + 26) = 32;
*((_DWORD *)&eof_main_menu + 56) = 32;
}
}

canonical_decompiled_code:
void func0()
{
bool v0; // zf

v0 = eof_song == 0LL;
*((_DWORD *)&eof_main_menu + 46) = 32;
if ( !v0 && eof_song_loaded )
{
*((_DWORD *)&eof_main_menu + 16) = 0;
*((_DWORD *)&eof_main_menu + 26) = 0;
*((_DWORD *)&eof_main_menu + 36) = 0;
*((_DWORD *)&eof_main_menu + 56) = 0;
if ( eof_count_selected_notes(0LL, 1LL) || eof_input_mode == 6 && eof_seek_hover_note >= 0 )
*((_DWORD *)&eof_main_menu + 46) = 0;
}
else
{
*((_DWORD *)&eof_main_menu + 16) = 32;
*((_DWORD *)&eof_main_menu + 26) = 32;
*((_DWORD *)&eof_main_menu + 56) = 32;
}
}

original_code:
void eof_prepare_main_menu(void)
{
 eof_main_menu[4].flags = 32;
 if(eof_song && eof_song_loaded)
 {
  eof_main_menu[1].flags = 0;
  eof_main_menu[2].flags = 0;
  eof_main_menu[3].flags = 0;
  eof_main_menu[5].flags = 0;
  if(eof_count_selected_notes(((void *)0), 1) || ((eof_input_mode == 6) && (eof_seek_hover_note >= 0)))
  {
   eof_main_menu[4].flags = 0;
  }
 }
 else
 {
  eof_main_menu[1].flags = 32;
  eof_main_menu[2].flags = 32;
  eof_main_menu[5].flags = 32;
 }
}

canonical_original_code:
void eof_prepare_main_menu()
{
 eof_main_menu[4].flags = 32;
 if(eof_song && eof_song_loaded)
 {
  eof_main_menu[1].flags = 0;
  eof_main_menu[2].flags = 0;
  eof_main_menu[3].flags = 0;
  eof_main_menu[5].flags = 0;
  if(eof_count_selected_notes(((void *)0), 1) || ((eof_input_mode == 6) && (eof_seek_hover_note >= 0)))
  {
   eof_main_menu[4].flags = 0;
  }
 }
 else
 {
  eof_main_menu[1].flags = 32;
  eof_main_menu[2].flags = 32;
  eof_main_menu[5].flags = 32;
 }
}

return_type: void


decompiled_code:
void __fastcall eof_window_destroy(void *ptr)
{
eof_log("eof_window_destroy() entered", 1LL);
if ( ptr )
{
destroy_bitmap(*((_QWORD *)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
eof_log("eof_window_destroy() entered", 1LL);
if ( ptr )
{
destroy_bitmap(*((_QWORD *)ptr + 2));
free(ptr);
}
}

original_code:
void eof_window_destroy(EOF_WINDOW * wp)
{
  eof_log("eof_window_destroy() entered", 1);
 if(wp)
 {
  destroy_bitmap(wp->screen);
  free(wp);
 }
}

canonical_original_code:
void eof_window_destroy(struct EOF_WINDOW *wp)
{
  eof_log("eof_window_destroy() entered", 1);
 if(wp)
 {
  destroy_bitmap(wp->screen);
  free(wp);
 }
}

variable_types: struct EOF_WINDOW { int x; int w; 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[]; } *screen; } *

user_defined_types: struct EOF_WINDOW { int x; int w; struct BITMAP *screen; }

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 eof_menu_help_keys()
{
void *v0; // rax
__int64 result; // rax

v0 = (void *)eof_buffer_file("keys.txt", 1LL);
eof_help_text = v0;
if ( v0 )
{
*(&eof_help_dialog + 24) = v0;
eof_cursor_visible = 0;
eof_pen_visible = 0;
eof_render();
eof_color_dialog(&eof_help_dialog, gui_fg_color, gui_bg_color);
centre_dialog(&eof_help_dialog);
eof_popup_dialog(&eof_help_dialog, 0LL);
eof_show_mouse(0LL);
eof_cursor_visible = 1;
eof_pen_visible = 1;
free(eof_help_text);
result = 1LL;
eof_help_text = 0LL;
}
else
{
allegro_message("Error reading keys.txt");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
void *v0; // rax
__int64 result; // rax

v0 = (void *)eof_buffer_file("keys.txt", 1LL);
eof_help_text = v0;
if ( v0 )
{
*(&eof_help_dialog + 24) = v0;
eof_cursor_visible = 0;
eof_pen_visible = 0;
eof_render();
eof_color_dialog(&eof_help_dialog, gui_fg_color, gui_bg_color);
centre_dialog(&eof_help_dialog);
eof_popup_dialog(&eof_help_dialog, 0LL);
eof_show_mouse(0LL);
eof_cursor_visible = 1;
eof_pen_visible = 1;
free(eof_help_text);
result = 1LL;
eof_help_text = 0LL;
}
else
{
allegro_message("Error reading keys.txt");
result = 1LL;
}
return result;
}

original_code:
int eof_menu_help_keys(void)
{
 eof_help_text = eof_buffer_file("keys.txt", 1);
 if(eof_help_text == ((void *)0))
 {
  allegro_message("Error reading keys.txt");
  return 1;
 }
 eof_help_dialog[2].dp = eof_help_text;
 eof_cursor_visible = 0;
 eof_pen_visible = 0;
 eof_render();
 eof_color_dialog(eof_help_dialog, gui_fg_color, gui_bg_color);
 centre_dialog(eof_help_dialog);
 if(eof_popup_dialog(eof_help_dialog, 0) == 1)
 {
 }
 eof_show_mouse(((void *)0));
 eof_cursor_visible = 1;
 eof_pen_visible = 1;
 free(eof_help_text);
 eof_help_text = ((void *)0);
 return 1;
}

canonical_original_code:
int eof_menu_help_keys()
{
 eof_help_text = eof_buffer_file("keys.txt", 1);
 if(eof_help_text == ((void *)0))
 {
  allegro_message("Error reading keys.txt");
  return 1;
 }
 eof_help_dialog[2].dp = eof_help_text;
 eof_cursor_visible = 0;
 eof_pen_visible = 0;
 eof_render();
 eof_color_dialog(eof_help_dialog, gui_fg_color, gui_bg_color);
 centre_dialog(eof_help_dialog);
 if(eof_popup_dialog(eof_help_dialog, 0) == 1)
 {
 }
 eof_show_mouse(((void *)0));
 eof_cursor_visible = 1;
 eof_pen_visible = 1;
 free(eof_help_text);
 eof_help_text = ((void *)0);
 return 1;
}


decompiled_code:
__int64 eof_menu_help_manual()
{
eof_system("xdg-open manual/index.htm");
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
eof_system("xdg-open manual/index.htm");
return 1LL;
}

original_code:
int eof_menu_help_manual(void)
{
   (void) eof_system("xdg-open manual/index.htm");
 return 1;
}

canonical_original_code:
int eof_menu_help_manual()
{
   (void) eof_system("xdg-open manual/index.htm");
 return 1;
}


decompiled_code:
__int64 eof_menu_help_tutorial()
{
eof_system("xdg-open tutorial/index.htm");
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
eof_system("xdg-open tutorial/index.htm");
return 1LL;
}

original_code:
int eof_menu_help_tutorial(void)
{
   (void) eof_system("xdg-open tutorial/index.htm");
 return 1;
}

canonical_original_code:
int eof_menu_help_tutorial()
{
   (void) eof_system("xdg-open tutorial/index.htm");
 return 1;
}


decompiled_code:
__int64 eof_menu_help_vocals_tutorial()
{
eof_system("xdg-open vocaltutorial/index.htm");
return 1LL;
}

canonical_decompiled_code:
__int64 func3()
{
eof_system("xdg-open vocaltutorial/index.htm");
return 1LL;
}

original_code:
int eof_menu_help_vocals_tutorial(void)
{
   (void) eof_system("xdg-open vocaltutorial/index.htm");
 return 1;
}

canonical_original_code:
int eof_menu_help_vocals_tutorial()
{
   (void) eof_system("xdg-open vocaltutorial/index.htm");
 return 1;
}


decompiled_code:
__int64 eof_menu_help_pro_guitar_tutorial()
{
eof_system("xdg-open proguitartutorial/index.htm");
return 1LL;
}

canonical_decompiled_code:
__int64 func4()
{
eof_system("xdg-open proguitartutorial/index.htm");
return 1LL;
}

original_code:
int eof_menu_help_pro_guitar_tutorial(void)
{
   (void) eof_system("xdg-open proguitartutorial/index.htm");
 return 1;
}

canonical_original_code:
int eof_menu_help_pro_guitar_tutorial()
{
   (void) eof_system("xdg-open proguitartutorial/index.htm");
 return 1;
}


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

eof_cursor_visible = 0;
eof_pen_visible = 0;
eof_render();
alert("EOF v1.8RC10", 0LL, "(c)2008-2010 T^3 Software.", "Okay", 0LL, 67LL, 0LL);
eof_clear_input();
eof_show_mouse(0LL);
result = 1LL;
eof_cursor_visible = 1;
eof_pen_visible = 1;
return result;
}

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

eof_cursor_visible = 0;
eof_pen_visible = 0;
eof_render();
alert("EOF v1.8RC10", 0LL, "(c)2008-2010 T^3 Software.", "Okay", 0LL, 67LL, 0LL);
eof_clear_input();
eof_show_mouse(0LL);
result = 1LL;
eof_cursor_visible = 1;
eof_pen_visible = 1;
return result;
}

original_code:
int eof_menu_help_about(void)
{
 eof_cursor_visible = 0;
 eof_pen_visible = 0;
 eof_render();
 (void) alert("EOF v1.8RC10", ((void *)0), "(c)2008-2010 T^3 Software.", "Okay", ((void *)0), __allegro_KEY_ENTER, 0);
 eof_clear_input();
 eof_show_mouse(((void *)0));
 eof_cursor_visible = 1;
 eof_pen_visible = 1;
 return 1;
}

canonical_original_code:
int eof_menu_help_about()
{
 eof_cursor_visible = 0;
 eof_pen_visible = 0;
 eof_render();
 (void) alert("EOF v1.8RC10", ((void *)0), "(c)2008-2010 T^3 Software.", "Okay", ((void *)0), __allegro_KEY_ENTER, 0);
 eof_clear_input();
 eof_show_mouse(((void *)0));
 eof_cursor_visible = 1;
 eof_pen_visible = 1;
 return 1;
}


decompiled_code:
void aalg_init()
{
gui_menu_draw_menu = 0LL;
gui_menu_draw_menu_item = 0LL;
qword_188 = (__int64)&gui_fg_color;
qword_190 = (__int64)&gui_bg_color;
qword_198 = (__int64)&gui_mg_color;
}

canonical_decompiled_code:
void func0()
{
gui_menu_draw_menu = 0LL;
gui_menu_draw_menu_item = 0LL;
qword_188 = (__int64)&gui_fg_color;
qword_190 = (__int64)&gui_bg_color;
qword_198 = (__int64)&gui_mg_color;
}

original_code:
void aalg_init(void)
{
    gui_menu_draw_menu = ((void *)0);
    gui_menu_draw_menu_item = ((void *)0);
    the_theme.fg_color = &gui_fg_color;
    the_theme.bg_color = &gui_bg_color;
    the_theme.mg_color = &gui_mg_color;
}

canonical_original_code:
void aalg_init()
{
    gui_menu_draw_menu = ((void *)0);
    gui_menu_draw_menu_item = ((void *)0);
    the_theme.fg_color = &gui_fg_color;
    the_theme.bg_color = &gui_bg_color;
    the_theme.mg_color = &gui_mg_color;
}


decompiled_code:
void aalg_shutdown()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void aalg_shutdown(void)
{
}

canonical_original_code:
void aalg_shutdown()
{
}


decompiled_code:
__int64 __fastcall d_aalg_window_proc(int a1, __int64 a2)
{
_DWORD *v3; // rbp
unsigned int v4; // er12
unsigned int v5; // er13
unsigned int v6; // er14
unsigned int v7; // er15

if ( a1 != 3 )
return 0LL;
d_shadow_box_proc();
if ( *(_QWORD *)(a2 + 48) )
{
v3 = (_DWORD *)gui_get_screen();
v4 = v3[3];
v5 = v3[5];
v6 = v3[4];
v7 = v3[6];
set_clip_rect(
v3,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
(unsigned int)(*(_DWORD *)(a2 + 8) + *(_DWORD *)(a2 + 16) - 1),
(unsigned int)(*(_DWORD *)(a2 + 12) + *(_DWORD *)(a2 + 20) - 1));
textout_ex(
v3,
font,
*(_QWORD *)(a2 + 48),
(unsigned int)(*(_DWORD *)(a2 + 8) + 6),
(unsigned int)(*(_DWORD *)(a2 + 12) + 6),
gui_fg_color,
gui_bg_color);
set_clip_rect(v3, v4, v5, v6, v7);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, __int64 a2)
{
_DWORD *v3; // rbp
unsigned int v4; // er12
unsigned int v5; // er13
unsigned int v6; // er14
unsigned int v7; // er15

if ( a1 != 3 )
return 0LL;
d_shadow_box_proc();
if ( *(_QWORD *)(a2 + 48) )
{
v3 = (_DWORD *)gui_get_screen();
v4 = v3[3];
v5 = v3[5];
v6 = v3[4];
v7 = v3[6];
set_clip_rect(
v3,
*(unsigned int *)(a2 + 8),
*(unsigned int *)(a2 + 12),
(unsigned int)(*(_DWORD *)(a2 + 8) + *(_DWORD *)(a2 + 16) - 1),
(unsigned int)(*(_DWORD *)(a2 + 12) + *(_DWORD *)(a2 + 20) - 1));
textout_ex(
v3,
font,
*(_QWORD *)(a2 + 48),
(unsigned int)(*(_DWORD *)(a2 + 8) + 6),
(unsigned int)(*(_DWORD *)(a2 + 12) + 6),
gui_fg_color,
gui_bg_color);
set_clip_rect(v3, v4, v5, v6, v7);
}
return 0LL;
}

original_code:
int d_aalg_window_proc(int msg, DIALOG *d, int c)
{
   (void)c;
   if (msg == 3) {
      d_shadow_box_proc(msg, d, c);
      if (d->dp) {
  BITMAP *bmp = gui_get_screen();
  int cl = bmp->cl, ct = bmp->ct, cr = bmp->cr, cb = bmp->cb;
  set_clip_rect(bmp, d->x, d->y, d->x+d->w-1, d->y+d->h-1);
  textout_ex(bmp, font, (char *)d->dp, d->x+6, d->y+6, gui_fg_color, gui_bg_color);
  set_clip_rect(bmp, cl, ct, cr, cb);
      }
   }
   return 0;
}

canonical_original_code:
int d_aalg_window_proc(int msg, struct DIALOG *d, int c)
{
   (void)c;
   if (msg == 3) {
      d_shadow_box_proc(msg, d, c);
      if (d->dp) {
  struct BITMAP *bmp = gui_get_screen();
  int cl = bmp->cl; int ct = bmp->ct; int cr = bmp->cr; int cb = bmp->cb;
  set_clip_rect(bmp, d->x, d->y, d->x+d->w-1, d->y+d->h-1);
  textout_ex(bmp, font, (char *)d->dp, d->x+6, d->y+6, gui_fg_color, gui_bg_color);
  set_clip_rect(bmp, cl, ct, cr, cb);
      }
   }
   return 0;
}

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

variable_types: ct int

variable_types: cr int

variable_types: cb int

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


decompiled_code:
__int64 eof_prepare_menus()
{
eof_log("eof_prepare_menus() entered", 2LL);
eof_prepare_main_menu();
eof_prepare_beat_menu();
eof_prepare_file_menu();
eof_prepare_edit_menu();
eof_prepare_song_menu();
eof_prepare_track_menu();
eof_prepare_note_menu();
return eof_prepare_context_menu();
}

canonical_decompiled_code:
__int64 func0()
{
eof_log("eof_prepare_menus() entered", 2LL);
eof_prepare_main_menu();
eof_prepare_beat_menu();
eof_prepare_file_menu();
eof_prepare_edit_menu();
eof_prepare_song_menu();
eof_prepare_track_menu();
eof_prepare_note_menu();
return eof_prepare_context_menu();
}

original_code:
void eof_prepare_menus(void)
{
 eof_log("eof_prepare_menus() entered", 2);
 eof_prepare_main_menu();
 eof_prepare_beat_menu();
 eof_prepare_file_menu();
 eof_prepare_edit_menu();
 eof_prepare_song_menu();
 eof_prepare_track_menu();
 eof_prepare_note_menu();
 eof_prepare_context_menu();
}

canonical_original_code:
void eof_prepare_menus()
{
 eof_log("eof_prepare_menus() entered", 2);
 eof_prepare_main_menu();
 eof_prepare_beat_menu();
 eof_prepare_file_menu();
 eof_prepare_edit_menu();
 eof_prepare_song_menu();
 eof_prepare_track_menu();
 eof_prepare_note_menu();
 eof_prepare_context_menu();
}


decompiled_code:
__int64 __fastcall eof_color_dialog(_QWORD *a1, int a2, int a3)
{
__int64 result; // rax
_QWORD *v5; // rdi

result = eof_log("eof_color_dialog() entered", 2LL);
if ( a1 && *a1 )
{
v5 = a1 + 9;
do
{
*((_DWORD *)v5 - 12) = a2;
v5 += 9;
*((_DWORD *)v5 - 29) = a3;
}
while ( *(v5 - 9) );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2, int a3)
{
__int64 result; // rax
_QWORD *v5; // rdi

result = eof_log("eof_color_dialog() entered", 2LL);
if ( a1 && *a1 )
{
v5 = a1 + 9;
do
{
*((_DWORD *)v5 - 12) = a2;
v5 += 9;
*((_DWORD *)v5 - 29) = a3;
}
while ( *(v5 - 9) );
}
return result;
}

original_code:
void eof_color_dialog(DIALOG * dp, int fg, int bg)
{
 int i;
 eof_log("eof_color_dialog() entered", 2);
 if(dp == ((void *)0))
  return;
 for(i = 0; dp[i].proc != ((void *)0); i++)
 {
  dp[i].fg = fg;
  dp[i].bg = bg;
 }
}

canonical_original_code:
void eof_color_dialog(struct DIALOG *dp, int fg, int bg)
{
 int i;
 eof_log("eof_color_dialog() entered", 2);
 if(dp == ((void *)0))
  return;
 for(i = 0; dp[i].proc != ((void *)0); i++)
 {
  dp[i].fg = fg;
  dp[i].bg = bg;
 }
}

variable_types: fg int

variable_types: bg int


decompiled_code:
__int64 __fastcall eof_popup_dialog(void **a1, unsigned int a2)
{
__int64 v2; // r14
int v3; // er13
int v4; // er12
__int64 v6; // rbp
unsigned __int64 v7; // rax
int v8; // edi
unsigned int v9; // ebx
__int64 result; // rax
char v11; // al

v2 = 397401LL;
v3 = 0;
v4 = 0;
eof_log("eof_popup_dialog() entered", 2LL);
eof_prepare_menus();
v6 = init_dialog(a1, a2);
eof_show_mouse(screen);
clear_keybuf();
while ( 1 )
{
eof_read_keyboard_input(0LL);
if ( eof_key_pressed )
{
if ( eof_key_code == 59 )
break;
if ( eof_key_char )
{
simulate_ukeypress(eof_key_uchar);
}
else if ( eof_key_code )
{
simulate_ukeypress(0LL);
}
}
if ( !(unsigned int)update_dialog(v6) )
break;
if ( *a1 != &d_agup_menu_proc )
goto LABEL_10;
v7 = (unsigned int)(eof_key_char - 98);
if ( (unsigned int)v7 <= 0x12 && _bittest64(&v2, v7) )
{
v11 = mouse_b;
*(_DWORD *)(v6 + 8) = 0;
eof_keyboard_shortcut = 1;
if ( (v11 & 1) == 0 )
goto LABEL_10;
eof_keyboard_shortcut = 2;
v8 = mouse_b & 1;
if ( (mouse_b & 1) != 0 )
goto LABEL_10;
goto LABEL_29;
}
v8 = *(_DWORD *)(v6 + 8);
if ( (mouse_b & 1) != 0 )
{
eof_keyboard_shortcut = 2;
LABEL_33:
if ( (mouse_b & 1) != 0 )
goto LABEL_17;
LABEL_29:
eof_keyboard_shortcut = 0;
goto LABEL_17;
}
if ( eof_keyboard_shortcut == 2 )
goto LABEL_33;
LABEL_17:
if ( v8 < 0 && !(eof_keyboard_shortcut | eof_key_shifts & 4) )
break;
LABEL_10:
if ( a1 == eof_song_properties_dialog && (unsigned int)ustrlen(eof_song_properties_dialog[150]) != v4 )
{
object_message((unsigned int)((_DWORD)eof_song_properties_dialog + 1296), 3LL, 0LL);
v4 = ustrlen(eof_song_properties_dialog[168]);
}
if ( a1 == (void **)&eof_file_new_windows_dialog )
{
if ( (*((_BYTE *)&eof_file_new_windows_dialog + 252) & 2) != 0 && (int)ustrlen(&eof_etext4) <= 0 )
{
*((_DWORD *)&eof_file_new_windows_dialog + 99) = 32;
object_message((unsigned int)((_DWORD)&eof_file_new_windows_dialog + 360), 3LL, 0LL);
v3 = 1;
}
else
{
*((_DWORD *)&eof_file_new_windows_dialog + 99) = 1;
if ( v3 )
{
v3 = 0;
object_message((unsigned int)((_DWORD)&eof_file_new_windows_dialog + 360), 3LL, 0LL);
}
}
}
if ( eof_key_pressed )
eof_use_key();
Idle(10LL);
}
v9 = shutdown_dialog(v6);
eof_clear_input();
gametime_reset();
eof_show_mouse(0LL);
result = v9;
eof_keyboard_shortcut = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void **a1, unsigned int a2)
{
__int64 v2; // r14
int v3; // er13
int v4; // er12
__int64 v6; // rbp
unsigned __int64 v7; // rax
int v8; // edi
unsigned int v9; // ebx
__int64 result; // rax
char v11; // al

v2 = 397401LL;
v3 = 0;
v4 = 0;
eof_log("eof_popup_dialog() entered", 2LL);
func0();
v6 = init_dialog(a1, a2);
eof_show_mouse(screen);
clear_keybuf();
while ( 1 )
{
eof_read_keyboard_input(0LL);
if ( eof_key_pressed )
{
if ( eof_key_code == 59 )
break;
if ( eof_key_char )
{
simulate_ukeypress(eof_key_uchar);
}
else if ( eof_key_code )
{
simulate_ukeypress(0LL);
}
}
if ( !(unsigned int)update_dialog(v6) )
break;
if ( *a1 != &d_agup_menu_proc )
goto LABEL_10;
v7 = (unsigned int)(eof_key_char - 98);
if ( (unsigned int)v7 <= 0x12 && _bittest64(&v2, v7) )
{
v11 = mouse_b;
*(_DWORD *)(v6 + 8) = 0;
eof_keyboard_shortcut = 1;
if ( (v11 & 1) == 0 )
goto LABEL_10;
eof_keyboard_shortcut = 2;
v8 = mouse_b & 1;
if ( (mouse_b & 1) != 0 )
goto LABEL_10;
goto LABEL_29;
}
v8 = *(_DWORD *)(v6 + 8);
if ( (mouse_b & 1) != 0 )
{
eof_keyboard_shortcut = 2;
LABEL_33:
if ( (mouse_b & 1) != 0 )
goto LABEL_17;
LABEL_29:
eof_keyboard_shortcut = 0;
goto LABEL_17;
}
if ( eof_keyboard_shortcut == 2 )
goto LABEL_33;
LABEL_17:
if ( v8 < 0 && !(eof_keyboard_shortcut | eof_key_shifts & 4) )
break;
LABEL_10:
if ( a1 == eof_song_properties_dialog && (unsigned int)ustrlen(eof_song_properties_dialog[150]) != v4 )
{
object_message((unsigned int)((_DWORD)eof_song_properties_dialog + 1296), 3LL, 0LL);
v4 = ustrlen(eof_song_properties_dialog[168]);
}
if ( a1 == (void **)&eof_file_new_windows_dialog )
{
if ( (*((_BYTE *)&eof_file_new_windows_dialog + 252) & 2) != 0 && (int)ustrlen(&eof_etext4) <= 0 )
{
*((_DWORD *)&eof_file_new_windows_dialog + 99) = 32;
object_message((unsigned int)((_DWORD)&eof_file_new_windows_dialog + 360), 3LL, 0LL);
v3 = 1;
}
else
{
*((_DWORD *)&eof_file_new_windows_dialog + 99) = 1;
if ( v3 )
{
v3 = 0;
object_message((unsigned int)((_DWORD)&eof_file_new_windows_dialog + 360), 3LL, 0LL);
}
}
}
if ( eof_key_pressed )
eof_use_key();
Idle(10LL);
}
v9 = shutdown_dialog(v6);
eof_clear_input();
gametime_reset();
eof_show_mouse(0LL);
result = v9;
eof_keyboard_shortcut = 0;
return result;
}

original_code:
int eof_popup_dialog(DIALOG * dp, int n)
{
 int ret;
 int oldlen = 0;
 int dflag = 0;
 DIALOG_PLAYER * player;
 eof_log("eof_popup_dialog() entered", 2);
 eof_prepare_menus();
 player = init_dialog(dp, n);
 eof_show_mouse(screen);
 clear_keybuf();
 while(1)
 {
  eof_read_keyboard_input(0);
  if(eof_key_pressed)
  {
   if(eof_key_code == __allegro_KEY_ESC)
   {
    break;
   }
   if(eof_key_char)
   {
    simulate_ukeypress(eof_key_uchar, eof_key_code);
   }
   else if(eof_key_code)
   {
    simulate_ukeypress(0, eof_key_code);
   }
  }
  if(!update_dialog(player))
  {
   break;
  }
  if(dp[0].proc == d_agup_menu_proc)
  {
   if(eof_key_char == 'f' || eof_key_char == 'e' || eof_key_char == 's' || eof_key_char == 't' || eof_key_char == 'n' || eof_key_char == 'b' || eof_key_char == 'h')
   {
    eof_keyboard_shortcut = 1;
    player->mouse_obj = 0;
   }
   if(mouse_b & 1)
   {
    eof_keyboard_shortcut = 2;
   }
   if((eof_keyboard_shortcut == 2) && !(mouse_b & 1))
   {
    eof_keyboard_shortcut = 0;
   }
   if(player->mouse_obj < 0)
   {
    if(!(eof_key_shifts & __allegro_KB_ALT_FLAG) && !eof_keyboard_shortcut)
    {
     break;
    }
   }
  }
  if(dp == eof_song_properties_dialog)
  {
   if(ustrlen(eof_song_properties_dialog[16].dp) != oldlen)
   {
    (void) object_message(&eof_song_properties_dialog[18], 3, 0);
    oldlen = ustrlen(eof_song_properties_dialog[18].dp);
   }
  }
  if(dp == eof_file_new_windows_dialog)
  {
   if((eof_file_new_windows_dialog[3].flags & 2) && (ustrlen(eof_etext4) <= 0))
   {
    eof_file_new_windows_dialog[5].flags = 32;
    (void) object_message(&eof_file_new_windows_dialog[5], 3, 0);
    dflag = 1;
   }
   else
   {
    eof_file_new_windows_dialog[5].flags = 1;
    if(dflag)
    {
     (void) object_message(&eof_file_new_windows_dialog[5], 3, 0);
     dflag = 0;
    }
   }
  }
  if(eof_key_pressed)
  {
   eof_use_key();
  }
  Idle(10);
 }
 ret = shutdown_dialog(player);
 eof_clear_input();
 gametime_reset();
 eof_show_mouse(((void *)0));
 eof_keyboard_shortcut = 0;
 return ret;
}

canonical_original_code:
int eof_popup_dialog(struct DIALOG *dp, int n)
{
 int ret;
 int oldlen = 0;
 int dflag = 0;
 struct DIALOG_PLAYER *player;
 eof_log("eof_popup_dialog() entered", 2);
 eof_prepare_menus();
 player = init_dialog(dp, n);
 eof_show_mouse(screen);
 clear_keybuf();
 while(1)
 {
  eof_read_keyboard_input(0);
  if(eof_key_pressed)
  {
   if(eof_key_code == __allegro_KEY_ESC)
   {
    break;
   }
   if(eof_key_char)
   {
    simulate_ukeypress(eof_key_uchar, eof_key_code);
   }
   else if(eof_key_code)
   {
    simulate_ukeypress(0, eof_key_code);
   }
  }
  if(!update_dialog(player))
  {
   break;
  }
  if(dp[0].proc == d_agup_menu_proc)
  {
   if(eof_key_char == 'f' || eof_key_char == 'e' || eof_key_char == 's' || eof_key_char == 't' || eof_key_char == 'n' || eof_key_char == 'b' || eof_key_char == 'h')
   {
    eof_keyboard_shortcut = 1;
    player->mouse_obj = 0;
   }
   if(mouse_b & 1)
   {
    eof_keyboard_shortcut = 2;
   }
   if((eof_keyboard_shortcut == 2) && !(mouse_b & 1))
   {
    eof_keyboard_shortcut = 0;
   }
   if(player->mouse_obj < 0)
   {
    if(!(eof_key_shifts & __allegro_KB_ALT_FLAG) && !eof_keyboard_shortcut)
    {
     break;
    }
   }
  }
  if(dp == eof_song_properties_dialog)
  {
   if(ustrlen(eof_song_properties_dialog[16].dp) != oldlen)
   {
    (void) object_message(&eof_song_properties_dialog[18], 3, 0);
    oldlen = ustrlen(eof_song_properties_dialog[18].dp);
   }
  }
  if(dp == eof_file_new_windows_dialog)
  {
   if((eof_file_new_windows_dialog[3].flags & 2) && (ustrlen(eof_etext4) <= 0))
   {
    eof_file_new_windows_dialog[5].flags = 32;
    (void) object_message(&eof_file_new_windows_dialog[5], 3, 0);
    dflag = 1;
   }
   else
   {
    eof_file_new_windows_dialog[5].flags = 1;
    if(dflag)
    {
     (void) object_message(&eof_file_new_windows_dialog[5], 3, 0);
     dflag = 0;
    }
   }
  }
  if(eof_key_pressed)
  {
   eof_use_key();
  }
  Idle(10);
 }
 ret = shutdown_dialog(player);
 eof_clear_input();
 gametime_reset();
 eof_show_mouse(((void *)0));
 eof_keyboard_shortcut = 0;
 return ret;
}

variable_types: n int

variable_types: ret int

variable_types: oldlen int

variable_types: dflag int

variable_types: struct DIALOG_PLAYER { int obj; int res; int mouse_obj; int focus_obj; int joy_on; int click_wait; int mouse_ox; int mouse_oz; int mouse_b; struct DIALOG { int (*proc)(int msg, struct DIALOG *d, int c); int x; int fg; int key; int flags; int d1; void *dp; } *dialog; } *

user_defined_types: struct DIALOG_PLAYER { int obj; int res; int mouse_obj; int focus_obj; int joy_on; int click_wait; int mouse_ox; int mouse_oz; int mouse_b; struct DIALOG *dialog; }


ConvertSRTTimestamp

original_code:
unsigned long ConvertSRTTimestamp(char **ptr,int *errorstatus)
{
 char *temp=((void *)0);
 unsigned int ctr=1;
 char failed=0;
 char hours[3 +1]={0};
 char minutes[3 +1]={0};
 char seconds[3 +1]={0};
 char millis[3 +1]={0};
 unsigned int index=0;
 unsigned long sum=0;
 long conversion=0;
 if(ptr == ((void *)0))
  failed=1;
 else
 {
  temp=*ptr;
  if(temp == ((void *)0))
   failed=1;
 }
 if((temp != ((void *)0)) && !((*__ctype_b_loc ())[(int) ((temp[0]))] & (unsigned short int) _ISdigit))
  failed=1;
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     hours[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 hours[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     minutes[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 minutes[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit) && (temp[ctr] != ',')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     seconds[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 seconds[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || !((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISdigit))
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short int) _ISspace) || (temp[ctr] == '\0'))
    break;
   else
    failed=1;
  }
  else
  {
   if(index > 3)
    failed=2;
   else
    millis[index++]=temp[ctr++];
  }
 }
 assert_wrapper(index < 3 +1);
 millis[index]='\0';
 if(failed)
 {
  printf("Error: Invalid timestamp \"%s\"\n",temp);
  if(errorstatus != ((void *)0))
  {
   *errorstatus=1;
   return 0;
  }
  else
  {
   (void) puts("Aborting");
   exit_wrapper(1);
  }
 }
 assert_wrapper((ptr != ((void *)0)) && (temp != ((void *)0)));
 *ptr=&(temp[ctr+1]);
 temp=RemoveLeadingZeroes(hours);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*3600000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(minutes);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*60000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(seconds);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=3;
    return 0;
   }
   else
    exit_wrapper(3);
  }
  sum+=conversion*1000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(millis);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=4;
    return 0;
   }
   else
    exit_wrapper(4);
  }
  sum+=conversion;
 }
 free(temp);
 return sum;
}

canonical_original_code:
unsigned long ConvertSRTTimestamp(char **ptr, int *errorstatus)
{
 char *temp = ((void *)0);
 unsigned int ctr = 1;
 char failed = 0;
 char hours[-1] = {0};
 char minutes[-1] = {0};
 char seconds[-1] = {0};
 char millis[-1] = {0};
 unsigned int index = 0;
 unsigned long sum = 0;
 long conversion = 0;
 if(ptr == ((void *)0))
  failed=1;
 else
 {
  temp=*ptr;
  if(temp == ((void *)0))
   failed=1;
 }
 if((temp != ((void *)0)) && !((*__ctype_b_loc ())[(int) ((temp[0]))] & (unsigned short) _ISdigit))
  failed=1;
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     hours[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 hours[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit) && (temp[ctr] != ':')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     minutes[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 minutes[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || (!((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit) && (temp[ctr] != ',')))
   failed=1;
  else
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
   {
    if(index > 3)
     failed=2;
    else
     seconds[index++]=temp[ctr++];
   }
   else
   {
    ctr++;
    break;
   }
  }
 }
 assert_wrapper(index < 3 +1);
 seconds[index]='\0';
 index=0;
 while(!failed)
 {
  assert_wrapper(temp != ((void *)0));
  if((temp[ctr] == '\0') || !((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISdigit))
  {
   if(((*__ctype_b_loc ())[(int) ((temp[ctr]))] & (unsigned short) _ISspace) || (temp[ctr] == '\0'))
    break;
   else
    failed=1;
  }
  else
  {
   if(index > 3)
    failed=2;
   else
    millis[index++]=temp[ctr++];
  }
 }
 assert_wrapper(index < 3 +1);
 millis[index]='\0';
 if(failed)
 {
  printf("Error: Invalid timestamp \"%s\"\n",temp);
  if(errorstatus != ((void *)0))
  {
   *errorstatus=1;
   return 0;
  }
  else
  {
   (void) puts("Aborting");
   exit_wrapper(1);
  }
 }
 assert_wrapper((ptr != ((void *)0)) && (temp != ((void *)0)));
 *ptr=&(temp[ctr+1]);
 temp=RemoveLeadingZeroes(hours);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*3600000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(minutes);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=2;
    return 0;
   }
   else
    exit_wrapper(2);
  }
  sum+=conversion*60000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(seconds);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=3;
    return 0;
   }
   else
    exit_wrapper(3);
  }
  sum+=conversion*1000;
 }
 free(temp);
 temp=RemoveLeadingZeroes(millis);
 if(temp[0] != '0')
 {
  conversion=atol(temp);
  if(conversion<1)
  {
   (void) puts("Error converting string to integer\nAborting");
   free(temp);
   if(errorstatus != ((void *)0))
   {
    *errorstatus=4;
    return 0;
   }
   else
    exit_wrapper(4);
  }
  sum+=conversion;
 }
 free(temp);
 return sum;
}

variable_types:
ptr
char **

variable_types:
errorstatus
int *

variable_types:
temp
char *

variable_types:
ctr
unsigned int

variable_types: failed char

variable_types:
hours
char [-1]

variable_types:
minutes
char [-1]

variable_types:
seconds
char [-1]

variable_types:
millis
char [-1]

variable_types:
index
unsigned int

variable_types:
sum
unsigned long

variable_types: conversion long

return_type: unsigned long


original_code:
static void eof_bpm_estimator_callback(void * buffer, int nsamples, int stereo)
{
 int i;
 unsigned short * buffer_sp = (unsigned short *)buffer;
 int iter = stereo ? 2 : 1;
 for(i = 0; i < nsamples / iter; i++)
 {
  eof_bpm_estimator_buffer[i] = (float)((long)buffer_sp[i * iter] - 0x8000) / (float)0x8000;
  if(stereo)
  {
   eof_bpm_estimator_buffer[i] += (float)((long)buffer_sp[i * iter + 1] - 0x8000) / (float)0x8000;
   eof_bpm_estimator_buffer[i] /= 2.0;
  }
 }
 minibpm_process(eof_bpm_estimator_state, eof_bpm_estimator_buffer, nsamples / iter);
}

canonical_original_code:
static void eof_bpm_estimator_callback(void *buffer, int nsamples, int stereo)
{
 int i;
 unsigned short *buffer_sp = (unsigned short *)buffer;
 int iter = stereo ? 2 : 1;
 for(i = 0; i < nsamples / iter; i++)
 {
  eof_bpm_estimator_buffer[i] = (float)((long)buffer_sp[i * iter] - 0x8000) / (float)0x8000;
  if(stereo)
  {
   eof_bpm_estimator_buffer[i] += (float)((long)buffer_sp[i * iter + 1] - 0x8000) / (float)0x8000;
   eof_bpm_estimator_buffer[i] /= 2.0;
  }
 }
 minibpm_process(eof_bpm_estimator_state, eof_bpm_estimator_buffer, nsamples / iter);
}

variable_types:
buffer
void *

variable_types: nsamples int

variable_types: stereo int

variable_types: i int

variable_types: iter int


original_code:
int EOF_TRANSFER_FROM_LC(EOF_VOCAL_TRACK * tp, struct _LYRICSSTRUCT_ * lp)
{
 struct Lyric_Line *curline;
 struct Lyric_Piece *curpiece;
 EOF_LYRIC *temp;
 unsigned long start=0;
 char startfound=0;
 char overdrive=0;
 eof_log("EOF_TRANSFER_FROM_LC() entered", 1);
 if((tp == ((void *)0)) || (lp == ((void *)0)))
  return -1;
 curline=lp->lines;
 while(curline != ((void *)0))
 {
  startfound = 0;
  overdrive = 0;
  curpiece=curline->pieces;
  while(curpiece != ((void *)0))
  {
   if((startfound == 0) && (curpiece->pitch != 96))
   {
    startfound = 1;
    start=curpiece->start;
   }
   if(curpiece->overdrive)
    overdrive = 1;
   temp=eof_vocal_track_add_lyric(tp);
   if(temp == ((void *)0))
    return -1;
   if((curpiece->pitch == 254) || (!lp->pitch_tracking))
    temp->note=0;
   else
    temp->note=(char)curpiece->pitch;
   temp->pos=curpiece->start;
   temp->length=(long)curpiece->duration;
   if(ustrlen(curpiece->lyric) > 255)
    return -1;
   if(curpiece->pitch == 96)
    (void) ustrzcpy(temp->text, 0x7fffffff, "");
   else
    (void) ustrzcpy(temp->text, 0x7fffffff, curpiece->lyric);
   if((curpiece->next == ((void *)0)) && startfound)
   {
    (void) eof_vocal_track_add_line(tp,start,curpiece->start + curpiece->duration);
    if(overdrive && (tp->lines > 0))
     tp->line[tp->lines-1].flags |= 1;
   }
   curpiece=curpiece->next;
  }
  curline=curline->next;
 }
 eof_log("\tLyrics imported", 1);
 return 0;
}

canonical_original_code:
int EOF_TRANSFER_FROM_LC(struct EOF_VOCAL_TRACK *tp, struct _LYRICSSTRUCT_ *lp)
{
 struct Lyric_Line *curline;
 struct Lyric_Piece *curpiece;
 struct EOF_LYRIC *temp;
 unsigned long start = 0;
 char startfound = 0;
 char overdrive = 0;
 eof_log("EOF_TRANSFER_FROM_LC() entered", 1);
 if((tp == ((void *)0)) || (lp == ((void *)0)))
  return -1;
 curline=lp->lines;
 while(curline != ((void *)0))
 {
  startfound = 0;
  overdrive = 0;
  curpiece=curline->pieces;
  while(curpiece != ((void *)0))
  {
   if((startfound == 0) && (curpiece->pitch != 96))
   {
    startfound = 1;
    start=curpiece->start;
   }
   if(curpiece->overdrive)
    overdrive = 1;
   temp=eof_vocal_track_add_lyric(tp);
   if(temp == ((void *)0))
    return -1;
   if((curpiece->pitch == 254) || (!lp->pitch_tracking))
    temp->note=0;
   else
    temp->note=(char)curpiece->pitch;
   temp->pos=curpiece->start;
   temp->length=(long)curpiece->duration;
   if(ustrlen(curpiece->lyric) > 255)
    return -1;
   if(curpiece->pitch == 96)
    (void) ustrzcpy(temp->text, 0x7fffffff, "");
   else
    (void) ustrzcpy(temp->text, 0x7fffffff, curpiece->lyric);
   if((curpiece->next == ((void *)0)) && startfound)
   {
    (void) eof_vocal_track_add_line(tp,start,curpiece->start + curpiece->duration);
    if(overdrive && (tp->lines > 0))
     tp->line[tp->lines-1].flags |= 1;
   }
   curpiece=curpiece->next;
  }
  curline=curline->next;
 }
 eof_log("\tLyrics imported", 1);
 return 0;
}

variable_types: struct EOF_VOCAL_TRACK { unsigned char toneset; struct EOF_TRACK_ENTRY { char track_format; char track_behavior; char track_type; unsigned long tracknum; char name[-1]; char altname[-1]; unsigned char difficulty; unsigned char numdiffs; unsigned long flags; } *parent; struct EOF_LYRIC { unsigned char type; unsigned char note; char text[-1]; unsigned long midi_pos; long midi_length; unsigned long pos; long length; unsigned long flags; unsigned char tflags; } *lyric[32768]; unsigned long lyrics; struct EOF_PHRASE_SECTION { unsigned long midi_start_pos; unsigned long midi_end_pos; unsigned long start_pos; unsigned long end_pos; unsigned long flags; char name[-1]; unsigned char difficulty; } line[4096]; unsigned long lines; } *

variable_types: struct _LYRICSSTRUCT_ { struct Lyric_Line { struct Lyric_Piece { unsigned long start; unsigned long duration; unsigned char pitch; char overdrive; char freestyle; char groupswithnext; char hasequal; char *lyric; char leadspace; char trailspace; struct Lyric_Piece *next; struct Lyric_Piece *prev; } *pieces; struct Lyric_Piece *curpiece; struct Lyric_Line *prev; struct Lyric_Line *next; unsigned long piececount; unsigned long start; unsigned long duration; } *lines; struct Lyric_Line *curline; struct Lyric_Piece *lastpiece; struct Lyric_Piece *prevlineslast; unsigned long linecount; char line_on; char lyric_defined; char lyric_on; char overdrive_on; char freestyle_on; char *TitleStringID; char *ArtistStringID; char *AlbumStringID; char *EditorStringID; char *OffsetStringID; char *YearStringID; char *Title; char *Artist; char *Album; char *Editor; char *Offset; char *Year; long realoffset; char offsetoverride; char srcoffsetoverride; long srcrealoffset; unsigned long startstamp; char nohyphens; char noplus; char grouping; char defaultfilter; char verbose; char quick; char pitch_tracking; char startstampspecified; char brute; char marklines; char nolyrics; char notenames; char relative; char nopitch; char reinit; char nofstyle; unsigned long piececount; char *filter; unsigned char in_format; unsigned char out_format; double explicittempo; unsigned char last_pitch; struct OmitID3frame { char *frameid; struct OmitID3frame *next; } *nosrctag; char rocksmithver; char *outfilename; char *infilename; char *srclyrname; char *srcrhythmname; char *dstlyrname; char *srcfilename; char *inputtrack; char *outputtrack; } *

variable_types:
start
unsigned long

variable_types: startfound char

variable_types: overdrive char

user_defined_types: struct EOF_VOCAL_TRACK { unsigned char toneset; struct EOF_TRACK_ENTRY *parent; struct EOF_LYRIC *lyric[32768]; unsigned long lyrics; struct EOF_PHRASE_SECTION line[4096]; unsigned long lines; }

user_defined_types: struct _LYRICSSTRUCT_ { struct Lyric_Line *lines; struct Lyric_Line *curline; struct Lyric_Piece *lastpiece; struct Lyric_Piece *prevlineslast; unsigned long linecount; char line_on; char lyric_defined; char lyric_on; char overdrive_on; char freestyle_on; char *TitleStringID; char *ArtistStringID; char *AlbumStringID; char *EditorStringID; char *OffsetStringID; char *YearStringID; char *Title; char *Artist; char *Album; char *Editor; char *Offset; char *Year; long realoffset; char offsetoverride; char srcoffsetoverride; long srcrealoffset; unsigned long startstamp; char nohyphens; char noplus; char grouping; char defaultfilter; char verbose; char quick; char pitch_tracking; char startstampspecified; char brute; char marklines; char nolyrics; char notenames; char relative; char nopitch; char reinit; char nofstyle; unsigned long piececount; char *filter; unsigned char in_format; unsigned char out_format; double explicittempo; unsigned char last_pitch; struct OmitID3frame *nosrctag; char rocksmithver; char *outfilename; char *infilename; char *srclyrname; char *srcrhythmname; char *dstlyrname; char *srcfilename; char *inputtrack; char *outputtrack; }

user_defined_types: struct Lyric_Line { struct Lyric_Piece *pieces; struct Lyric_Piece *curpiece; struct Lyric_Line *prev; struct Lyric_Line *next; unsigned long piececount; unsigned long start; unsigned long duration; }


repo: cinsk/xobstack

decompiled_code:
void __noreturn print_and_abort()
{
fprintf(stderr, "%s\n", "memory exhausted");
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fprintf(stderr, "%s\n", "memory exhausted");
exit(1);
}

original_code:
static void
__attribute__ ((noreturn))
print_and_abort (void)
{
  fprintf (stderr, "%s\n", "memory exhausted");
  exit (1);
}

canonical_original_code:
static void print_and_abort()
{
  fprintf (stderr, "%s\n", "memory exhausted");
  exit (1);
}


original_code:
void
xobs_free (struct xobs *h, void *obj)
{
  register struct _xobs_chunk *lp;
  register struct _xobs_chunk *plp;
  lp = h->chunk;
  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    {
      plp = lp->prev;
      do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)->extra_arg, (lp)); else (*(void (*) (void *)) (h)->freefun) ((lp)); } while (0);
      lp = plp;
      h->maybe_empty_object = 1;
    }
  if (lp)
    {
      h->object_base = h->next_free = (char *) (obj);
      h->chunk_limit = lp->limit;
      h->chunk = lp;
    }
  else if (obj != 0)
    abort ();
}

canonical_original_code:
void xobs_free(struct xobs *h, void *obj)
{
  register struct _xobs_chunk *lp;
  register struct _xobs_chunk *plp;
  lp = h->chunk;
  while (lp != 0 && ((void *) lp >= obj || (void *) (lp)->limit < obj))
    {
      plp = lp->prev;
      do { if ((h) -> use_extra_arg) (*(h)->freefun) ((h)->extra_arg, (lp)); else (*(void (*)(void *)) (h)->freefun) ((lp)); } while (0);
      lp = plp;
      h->maybe_empty_object = 1;
    }
  if (lp)
    {
      h->object_base = h->next_free = (char *) (obj);
      h->chunk_limit = lp->limit;
      h->chunk = lp;
    }
  else if (obj != 0)
    abort ();
}

variable_types: struct xobs { long chunk_size; struct _xobs_chunk { char *limit; struct _xobs_chunk *prev; char contents[4]; } *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _xobs_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _xobs_chunk *); void (*failfun)(struct xobs *self); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; } *

variable_types:
obj
void *

user_defined_types: struct xobs { long chunk_size; struct _xobs_chunk *chunk; char *object_base; char *next_free; char *chunk_limit; union { long tempint; void *tempptr; } temp; int alignment_mask; struct _xobs_chunk *(*chunkfun)(void *, long); void (*freefun)(void *, struct _xobs_chunk *); void (*failfun)(struct xobs *self); void *extra_arg; unsigned int use_extra_arg; unsigned int maybe_empty_object; }


decompiled_code:
__int64 xobs_sprintf_(_QWORD *a1, const char *a2, ...)
{
int v4; // eax
int v5; // esi
int v6; // er12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
void (__fastcall *v11)(_QWORD *); // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v4 = vsnprintf(0LL, 0LL, a2, arg);
v5 = v4 + 1;
v6 = v4;
v7 = a1[3];
if ( a1[4] - v7 >= v5 )
goto LABEL_2;
if ( (unsigned int)_xobs_newchunk(a1) )
{
v7 = a1[3];
LABEL_2:
v8 = v5 + v7;
a1[3] = v8;
goto LABEL_3;
}
v11 = (void (__fastcall *)(_QWORD *))a1[9];
if ( v11 )
{
v11(a1);
v8 = a1[3];
}
else
{
if ( xobs_alloc_failed_handler )
xobs_alloc_failed_handler(a1);
v8 = a1[3];
}
LABEL_3:
v9 = a1[2];
va_end(arg);
va_start(arg, a2);
vsnprintf((char *)(~(__int64)v6 + (unsigned int)(v8 - v9) + v9), v5, a2, arg);
--a1[3];
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 func14(_QWORD *a1, const char *a2, ...)
{
int v4; // eax
int v5; // esi
int v6; // er12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
void (__fastcall *v11)(_QWORD *); // rax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v4 = vsnprintf(0LL, 0LL, a2, arg);
v5 = v4 + 1;
v6 = v4;
v7 = a1[3];
if ( a1[4] - v7 >= v5 )
goto LABEL_2;
if ( (unsigned int)_xobs_newchunk(a1) )
{
v7 = a1[3];
LABEL_2:
v8 = v5 + v7;
a1[3] = v8;
goto LABEL_3;
}
v11 = (void (__fastcall *)(_QWORD *))a1[9];
if ( v11 )
{
v11(a1);
v8 = a1[3];
}
else
{
if ( xobs_alloc_failed_handler )
xobs_alloc_failed_handler(a1);
v8 = a1[3];
}
LABEL_3:
v9 = a1[2];
va_end(arg);
va_start(arg, a2);
vsnprintf((char *)(~(__int64)v6 + (unsigned int)(v8 - v9) + v9), v5, a2, arg);
--a1[3];
return (unsigned int)v6;
}

original_code:
int
xobs_sprintf_(struct xobs *obs, const char *format, ...)
{
  int len;
  va_list ap;
  char *p;
  __builtin_va_start(ap,format);
  len = vsnprintf(((void *)0), 0, format, ap);
  __builtin_va_end(ap);
  __extension__ ({ struct xobs *__o = (obs); int __len = (len + 1); int ___ok = 1; if (__o->chunk_limit - __o->next_free < __len) ___ok = _xobs_newchunk (__o, __len); if (___ok) ((__o)->next_free += (__len)); else do { if ((__o)->failfun) (*(__o)->failfun)(__o); else if (xobs_alloc_failed_handler) (*xobs_alloc_failed_handler)(); } while (0); ___ok; });
  p = ((void *) ((obs)->object_base)) + __extension__ ({ struct xobs const *__o = (obs); (unsigned) (__o->next_free - __o->object_base); }) - (len + 1);
  __builtin_va_start(ap,format);
  vsnprintf(p, len + 1, format, ap);
  __builtin_va_end(ap);
  obs->next_free--;
  return len;
}

canonical_original_code:
int xobs_sprintf_(struct xobs *obs, char *format, ...)
{
  int len;
  __builtin_va_list ap;
  char *p;
  __builtin_va_start(ap,format);
  len = vsnprintf(((void *)0), 0, format, ap);
  __builtin_va_end(ap);
  __extension__ ({ struct xobs *__o = (obs); int __len = (len + 1); int ___ok = 1; if (__o->chunk_limit - __o->next_free < __len) ___ok = _xobs_newchunk (__o, __len); if (___ok) ((__o)->next_free += (__len)); else do { if ((__o)->failfun) (*(__o)->failfun)(__o); else if (xobs_alloc_failed_handler) (*xobs_alloc_failed_handler)(); } while (0); ___ok; });
  p = ((void *) ((obs)->object_base)) + __extension__ ({ struct xobs *__o = (obs); (unsigned int) (__o->next_free - __o->object_base); }) - (len + 1);
  __builtin_va_start(ap,format);
  vsnprintf(p, len + 1, format, ap);
  __builtin_va_end(ap);
  obs->next_free--;
  return len;
}

variable_types:
format
char *

variable_types: len int

variable_types:
p
char *

user_defined_types: struct _xobs_chunk { char *limit; struct _xobs_chunk *prev; char contents[4]; }


main

canonical_name: main

repo: ciuncan/HuffmanDecompress

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
{
argv[1] = "file2.txt";
argv[2] = "file3.txt";
}
createDecompressedFile(argv[1], argv[2], envp);
printOutputAsCharacters(argv[2]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
{
argv[1] = "file2.txt";
argv[2] = "file3.txt";
}
func15(argv[1], argv[2], envp);
func16(argv[2]);
return 0;
}

original_code:
int main(int argc, char** argv) {
    if(argc < 3) {
        argv[1] = "file2.txt";
        argv[2] = "file3.txt";
    }
    createDecompressedFile(argv[1], argv[2]);
    printOutputAsCharacters(argv[2]);
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    if(argc < 3) {
        argv[1] = "file2.txt";
        argv[2] = "file3.txt";
    }
    createDecompressedFile(argv[1], argv[2]);
    printOutputAsCharacters(argv[2]);
    return (0);
}

variable_types: argc int

variable_types:
argv
char **


toDecimal

decompiled_code:
__int64 __fastcall toDecimal(__int64 a1, int a2)
{
int v2; // esi
__int64 v3; // rax
unsigned int v4; // er8
int v5; // edx
char v6; // cl

v2 = a2 - 1;
if ( v2 < 0 )
return 0LL;
v3 = v2;
v4 = 0;
do
{
v5 = *(unsigned __int8 *)(a1 + v3);
v6 = v2 - v3--;
v4 |= v5 << v6;
}
while ( (int)v3 >= 0 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v2; // esi
__int64 v3; // rax
unsigned int v4; // er8
int v5; // edx
char v6; // cl

v2 = a2 - 1;
if ( v2 < 0 )
return 0LL;
v3 = v2;
v4 = 0;
do
{
v5 = *(unsigned __int8 *)(a1 + v3);
v6 = v2 - v3--;
v4 |= v5 << v6;
}
while ( (int)v3 >= 0 );
return v4;
}

original_code:
int toDecimal(unsigned char* bits, int length) {
    int i;
    int val = 0;
    for(i = length-1; i >= 0; --i) {
        val |= bits[i] << (length - i - 1);
    }
    return val;
}

canonical_original_code:
int toDecimal(unsigned char *bits, int length) {
    int i;
    int val = 0;
    for(i = length-1; i >= 0; --i) {
        val |= bits[i] << (length - i - 1);
    }
    return val;
}

variable_types:
bits
unsigned char *

variable_types: length int

variable_types: val int


equals

decompiled_code:
__int64 __fastcall equals(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 )
return 1LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rax

if ( a3 <= 0 )
return 1LL;
v3 = 0LL;
while ( *(_BYTE *)(a1 + v3) == *(_BYTE *)(a2 + v3) )
{
if ( ++v3 == a3 )
return 1LL;
}
return 0LL;
}

original_code:
int equals(unsigned char* first, unsigned char* second, int length) {
    int i;
    for(i = 0; i < length; ++i) {
        if(first[i] != second[i]) {
            return 0;
        }
    }
    return 1;
}

canonical_original_code:
int equals(unsigned char *first, unsigned char *second, int length) {
    int i;
    for(i = 0; i < length; ++i) {
        if(first[i] != second[i]) {
            return 0;
        }
    }
    return 1;
}

variable_types:
first
unsigned char *

variable_types:
second
unsigned char *

variable_types: i int


searchForCode

decompiled_code:
__int64 __fastcall searchForCode(__int64 a1, int a2)
{
__int64 i; // r8
__int64 v5; // r8

for ( i = 0LL; i != 255; i = v5 + 1 )
{
if ( (unsigned int)equals(codes[i], a1, a2) )
return (unsigned int)v5;
}
return 42LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
__int64 i; // r8
__int64 v5; // r8

for ( i = 0LL; i != 255; i = v5 + 1 )
{
if ( (unsigned int)func12(codes[i], a1, a2) )
return (unsigned int)v5;
}
return 42LL;
}

original_code:
char searchForCode(unsigned char* code, int length) {
    int i;
    for(i = 0; i < 255; ++i) {
        if(equals(codes[i], code, length)) {
            return (char) i;
        }
    }
    return '*';
}

canonical_original_code:
char searchForCode(unsigned char *code, int length) {
    int i;
    for(i = 0; i < 255; ++i) {
        if(equals(codes[i], code, length)) {
            return (char) i;
        }
    }
    return '*';
}

variable_types:
code
unsigned char *

return_type: char


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

if ( a1 == 128 )
return 13LL;
if ( a1 > 0x80 )
{
if ( a1 == 2048 )
{
result = 14LL;
}
else if ( a1 <= 0x800 )
{
result = 8LL;
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = 9LL;
}
else
{
result = 0LL;
if ( a1 == 256 )
result = 7LL;
}
}
}
else
{
result = 11LL;
if ( a1 != 0x4000 )
{
if ( a1 == 0x8000 )
{
result = 15LL;
}
else
{
result = 0LL;
if ( a1 == 4096 )
result = 10LL;
}
}
}
}
else if ( a1 > 0x20 )
{
result = 0LL;
if ( a1 == 64 )
result = 6LL;
}
else if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 1LL;
break;
case 2u:
result = 2LL;
break;
case 4u:
result = 3LL;
break;
case 8u:
result = 12LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
goto LABEL_6;
}
}
else
{
LABEL_6:
result = 0LL;
}
return result;
}

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

if ( a1 == 128 )
return 13LL;
if ( a1 > 0x80 )
{
if ( a1 == 2048 )
{
result = 14LL;
}
else if ( a1 <= 0x800 )
{
result = 8LL;
if ( a1 != 512 )
{
if ( a1 == 1024 )
{
result = 9LL;
}
else
{
result = 0LL;
if ( a1 == 256 )
result = 7LL;
}
}
}
else
{
result = 11LL;
if ( a1 != 0x4000 )
{
if ( a1 == 0x8000 )
{
result = 15LL;
}
else
{
result = 0LL;
if ( a1 == 4096 )
result = 10LL;
}
}
}
}
else if ( a1 > 0x20 )
{
result = 0LL;
if ( a1 == 64 )
result = 6LL;
}
else if ( a1 )
{
switch ( a1 )
{
case 1u:
result = 1LL;
break;
case 2u:
result = 2LL;
break;
case 4u:
result = 3LL;
break;
case 8u:
result = 12LL;
break;
case 0x10u:
result = 4LL;
break;
case 0x20u:
result = 5LL;
break;
default:
goto LABEL_6;
}
}
else
{
LABEL_6:
result = 0LL;
}
return result;
}

original_code:
uint8_t key_value(enum chip8_key key)
{
 switch(key)
 {
  case KEY_0:
   return 0x0;
  case KEY_1:
   return 0x1;
  case KEY_2:
   return 0x2;
  case KEY_3:
   return 0x3;
  case KEY_4:
   return 0x4;
  case KEY_5:
   return 0x5;
  case KEY_6:
   return 0x6;
  case KEY_7:
   return 0x7;
  case KEY_8:
   return 0x8;
  case KEY_9:
   return 0x9;
  case KEY_A:
   return 0xA;
  case KEY_B:
   return 0xB;
  case KEY_C:
   return 0xC;
  case KEY_D:
   return 0xD;
  case KEY_E:
   return 0xE;
  case KEY_F:
   return 0xF;
 }
 return 0x0;
}

canonical_original_code:
unsigned char key_value(enum chip8_key key)
{
 switch(key)
 {
  case KEY_0:
   return 0x0;
  case KEY_1:
   return 0x1;
  case KEY_2:
   return 0x2;
  case KEY_3:
   return 0x3;
  case KEY_4:
   return 0x4;
  case KEY_5:
   return 0x5;
  case KEY_6:
   return 0x6;
  case KEY_7:
   return 0x7;
  case KEY_8:
   return 0x8;
  case KEY_9:
   return 0x9;
  case KEY_A:
   return 0xA;
  case KEY_B:
   return 0xB;
  case KEY_C:
   return 0xC;
  case KEY_D:
   return 0xD;
  case KEY_E:
   return 0xE;
  case KEY_F:
   return 0xF;
 }
 return 0x0;
}

return_type: unsigned char


decompiled_code:
__int16 __fastcall keypad_helper(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8)
{
__int16 v8; // dx
__int16 v9; // ax
__int16 v10; // dx
__int16 result; // ax

switch ( a8 )
{
case 'b':
v8 = 2048;
break;
case 'c':
v8 = 512;
break;
case 'd':
v8 = 32;
break;
case 'e':
v8 = 2;
break;
case 'f':
v8 = 64;
break;
case 'g':
v8 = 128;
break;
case 'h':
v8 = 4096;
break;
case 'j':
v8 = 0x2000;
break;
case 'k':
v8 = 0x4000;
break;
case 'l':
v8 = 0x8000;
break;
case 'q':
*(_BYTE *)(a1 + 54) = 8;
goto LABEL_3;
case 'r':
v8 = 4;
break;
case 's':
v8 = 16;
break;
case 't':
v8 = 8;
break;
case 'v':
v8 = 1024;
break;
case 'w':
v8 = 1;
break;
case 'x':
v8 = 256;
break;
default:
LABEL_3:
v8 = 0;
break;
}
v9 = v8;
v10 = *(_WORD *)(a1 + 2108) | v8;
result = *(_WORD *)(a1 + 2108) & ~v9;
if ( a7 == 2 )
result = v10;
*(_WORD *)(a1 + 2108) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7, int a8)
{
__int16 v8; // dx
__int16 v9; // ax
__int16 v10; // dx
__int16 result; // ax

switch ( a8 )
{
case 'b':
v8 = 2048;
break;
case 'c':
v8 = 512;
break;
case 'd':
v8 = 32;
break;
case 'e':
v8 = 2;
break;
case 'f':
v8 = 64;
break;
case 'g':
v8 = 128;
break;
case 'h':
v8 = 4096;
break;
case 'j':
v8 = 0x2000;
break;
case 'k':
v8 = 0x4000;
break;
case 'l':
v8 = 0x8000;
break;
case 'q':
*(_BYTE *)(a1 + 54) = 8;
goto LABEL_3;
case 'r':
v8 = 4;
break;
case 's':
v8 = 16;
break;
case 't':
v8 = 8;
break;
case 'v':
v8 = 1024;
break;
case 'w':
v8 = 1;
break;
case 'x':
v8 = 256;
break;
default:
LABEL_3:
v8 = 0;
break;
}
v9 = v8;
v10 = *(_WORD *)(a1 + 2108) | v8;
result = *(_WORD *)(a1 + 2108) & ~v9;
if ( a7 == 2 )
result = v10;
*(_WORD *)(a1 + 2108) = result;
return result;
}

original_code:
void keypad_helper(cpu_t* cpu,SDL_KeyboardEvent ke)
{
 enum chip8_key affected_key;
 switch(ke.keysym.sym)
 {
  case SDLK_w:
   affected_key = KEY_1;
   break;
  case SDLK_e:
   affected_key = KEY_2;
   break;
  case SDLK_r:
   affected_key = KEY_3;
   break;
  case SDLK_t:
   affected_key = KEY_C;
   break;
  case SDLK_s:
   affected_key = KEY_4;
   break;
  case SDLK_d:
   affected_key = KEY_5;
   break;
  case SDLK_f:
   affected_key = KEY_6;
   break;
  case SDLK_g:
   affected_key = KEY_D;
   break;
  case SDLK_x:
   affected_key = KEY_7;
   break;
  case SDLK_c:
   affected_key = KEY_8;
   break;
  case SDLK_v:
   affected_key = KEY_9;
   break;
  case SDLK_b:
   affected_key = KEY_E;
   break;
  case SDLK_h:
   affected_key = KEY_A;
   break;
  case SDLK_j:
   affected_key = KEY_0;
   break;
  case SDLK_k:
   affected_key = KEY_B;
   break;
  case SDLK_l:
   affected_key = KEY_F;
   break;
  case SDLK_q:
   cpu->errno = EUSRQ;
   break;
  default:
   break;
 }
 if(ke.type == SDL_KEYDOWN)
 {
  cpu->keypad |= affected_key;
 }
 else
 {
  cpu->keypad &= ~affected_key;
 }
}

canonical_original_code:
void keypad_helper(struct cpu_t *cpu, struct SDL_KeyboardEvent ke)
{
 enum chip8_key affected_key;
 switch(ke.keysym.sym)
 {
  case SDLK_w:
   affected_key = KEY_1;
   break;
  case SDLK_e:
   affected_key = KEY_2;
   break;
  case SDLK_r:
   affected_key = KEY_3;
   break;
  case SDLK_t:
   affected_key = KEY_C;
   break;
  case SDLK_s:
   affected_key = KEY_4;
   break;
  case SDLK_d:
   affected_key = KEY_5;
   break;
  case SDLK_f:
   affected_key = KEY_6;
   break;
  case SDLK_g:
   affected_key = KEY_D;
   break;
  case SDLK_x:
   affected_key = KEY_7;
   break;
  case SDLK_c:
   affected_key = KEY_8;
   break;
  case SDLK_v:
   affected_key = KEY_9;
   break;
  case SDLK_b:
   affected_key = KEY_E;
   break;
  case SDLK_h:
   affected_key = KEY_A;
   break;
  case SDLK_j:
   affected_key = KEY_0;
   break;
  case SDLK_k:
   affected_key = KEY_B;
   break;
  case SDLK_l:
   affected_key = KEY_F;
   break;
  case SDLK_q:
   cpu->errno = EUSRQ;
   break;
  default:
   break;
 }
 if(ke.type == SDL_KEYDOWN)
 {
  cpu->keypad |= affected_key;
 }
 else
 {
  cpu->keypad &= ~affected_key;
 }
}

variable_types: struct cpu_t { unsigned char registers[16]; unsigned char delay; unsigned char sound; unsigned char stack_pointer; unsigned short pc; unsigned short stack[16]; unsigned char errno; unsigned short address; unsigned char screen[64][32]; unsigned char draw; unsigned short keypad; unsigned char *memory; enum boolean { b_FALSE=0, b_TRUE=1 } wait; unsigned short breakpoint; enum boolean { b_FALSE=0, b_TRUE=1 } stepping; } *

variable_types: struct SDL_KeyboardEvent { unsigned char type; unsigned char which; unsigned char state; struct SDL_keysym { unsigned char scancode; enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 } sym; enum SDLMod { KMOD_NONE=0, KMOD_LSHIFT=1, KMOD_RSHIFT=2, KMOD_LCTRL=64, KMOD_RCTRL=128, KMOD_LALT=256, KMOD_RALT=512, KMOD_LMETA=1024, KMOD_RMETA=2048, KMOD_NUM=4096, KMOD_CAPS=8192, KMOD_MODE=16384, KMOD_RESERVED=32768 } mod; unsigned short unicode; } keysym; }

user_defined_types: struct SDL_KeyboardEvent { unsigned char type; unsigned char which; unsigned char state; struct SDL_keysym keysym; }

user_defined_types: struct cpu_t { unsigned char registers[16]; unsigned char delay; unsigned char sound; unsigned char stack_pointer; unsigned short pc; unsigned short stack[16]; unsigned char errno; unsigned short address; unsigned char screen[64][32]; unsigned char draw; unsigned short keypad; unsigned char *memory; enum boolean wait; unsigned short breakpoint; enum boolean stepping; }

user_defined_types: struct SDL_keysym { unsigned char scancode; enum SDLKey sym; enum SDLMod mod; unsigned short unicode; }


main

repo: cjpl/daq

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r8
__int16 v4; // bx
__int64 v5; // rdi
__int64 v6; // rdx
__int16 v8; // ax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( (unsigned int)(argc - 3) > 1 )
goto LABEL_10;
v3 = argv[1];
if ( strcmp(v3, "V1718") )
{
if ( !strcmp(v3, "V2718") )
{
if ( argc != 4 )
{
puts(" CAENVMEDemo V2718 <VMEDevice> <VMELink>");
exit(1);
}
v4 = atoi(argv[2]);
v5 = 1LL;
v6 = (unsigned int)(__int16)atoi(argv[3]);
goto LABEL_6;
}
LABEL_10:
puts("Usage: CAENVMEDemo V1718 <VMEDevice>");
puts(" CAENVMEDemo V2718 <VMEDevice> <VMELink>");
exit(1);
}
if ( argc != 3 )
{
puts(" CAENVMEDemo V1718 <VMEDevice>");
exit(1);
}
v8 = atoi(argv[2]);
v6 = 0LL;
v5 = 0LL;
v4 = v8;
LABEL_6:
if ( (unsigned int)CAENVME_Init(v5, (unsigned int)v4, v6, v9) )
{
puts("\n\n Error opening the device");
exit(1);
}
con_init();
CaenVmeManual((int)v9[0], 1LL);
con_end();
CAENVME_End(v9[0]);
return 0;
}

original_code:
int main(int argc, void *argv[])
{
    CVBoardTypes VMEBoard;
    short Link;
    short Device;
    int32_t BHandle;
    if( (argc != 3) && (argc != 4) )
    {
        printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
        printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
        exit(1);
    }
    else
    {
        if( strcmp((char*)argv[1], "V1718") == 0 )
        {
            if( argc == 3 )
            {
                VMEBoard = cvV1718;
                Device = atoi((const char*)argv[2]);
                Link = 0;
            }
            else
            {
                printf("       CAENVMEDemo V1718 <VMEDevice>\n");
                exit(1);
            }
        }
        else
        {
            if( strcmp((char*)argv[1], "V2718") == 0 )
            {
                if( argc == 4 )
                {
                    Device = atoi((const char*) argv[2]);
                    Link = atoi((const char*) argv[3]);
                    VMEBoard = cvV2718;
                }
                else
                {
                    printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                    exit(1);
                }
            }
            else
            {
                printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
                printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                exit(1);
            }
        }
    }
    if( CAENVME_Init(VMEBoard, Device, Link, &BHandle) != cvSuccess )
    {
        printf("\n\n Error opening the device\n");
        exit(1);
    }
    con_init() ;
    CaenVmeManual(BHandle,1) ;
    con_end() ;
    CAENVME_End(BHandle);
}

canonical_original_code:
int main(int argc, void *argv[])
{
    enum CVBoardTypes VMEBoard;
    short Link;
    short Device;
    int BHandle;
    if( (argc != 3) && (argc != 4) )
    {
        printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
        printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
        exit(1);
    }
    else
    {
        if( strcmp((char *)argv[1], "V1718") == 0 )
        {
            if( argc == 3 )
            {
                VMEBoard = cvV1718;
                Device = atoi((char *)argv[2]);
                Link = 0;
            }
            else
            {
                printf("       CAENVMEDemo V1718 <VMEDevice>\n");
                exit(1);
            }
        }
        else
        {
            if( strcmp((char *)argv[1], "V2718") == 0 )
            {
                if( argc == 4 )
                {
                    Device = atoi((char *) argv[2]);
                    Link = atoi((char *) argv[3]);
                    VMEBoard = cvV2718;
                }
                else
                {
                    printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                    exit(1);
                }
            }
            else
            {
                printf("Usage: CAENVMEDemo V1718 <VMEDevice>\n");
                printf("       CAENVMEDemo V2718 <VMEDevice> <VMELink>\n");
                exit(1);
            }
        }
    }
    if( CAENVME_Init(VMEBoard, Device, Link, &BHandle) != cvSuccess )
    {
        printf("\n\n Error opening the device\n");
        exit(1);
    }
    con_init() ;
    CaenVmeManual(BHandle,1) ;
    con_end() ;
    CAENVME_End(BHandle);
}

variable_types:
argv
void *[]

variable_types: Link short

variable_types: Device short

variable_types: BHandle int


decompiled_code:
int con_init()
{
initscr();
cbreak();
noecho();
nodelay(stdscr, 0);
return curs_set(0);
}

canonical_decompiled_code:
int func0()
{
initscr();
cbreak();
noecho();
nodelay(stdscr, 0);
return curs_set(0);
}

original_code:
void con_init()
{
    initscr();
    cbreak();
    noecho();
    nodelay(stdscr, 0);
    curs_set(0);
}


decompiled_code:
// attributes: thunk
int con_end(void)
{
return endwin();
}

canonical_decompiled_code:
int func1(void)
{
return endwin();
}

original_code:
void con_end()
{
    endwin();
}

canonical_original_code:
void con_end()
{
    endwin();
}


decompiled_code:
int __fastcall write_log(const char *a1)
{
FILE *v2; // rdi

v2 = (FILE *)log_file;
if ( !log_file )
{
log_file = fopen(LOG_FILE_NAME, "w");
v2 = (FILE *)log_file;
if ( !log_file )
{
puts("\n\nCan't open log file\n");
exit(0);
}
}
fprintf(v2, "%s\n", a1);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
FILE *v2; // rdi

v2 = (FILE *)log_file;
if ( !log_file )
{
log_file = fopen(LOG_FILE_NAME, "w");
v2 = (FILE *)log_file;
if ( !log_file )
{
puts("\n\nCan't open log file\n");
exit(0);
}
}
fprintf(v2, "%s\n", a1);
return fflush(stdout);
}

original_code:
void write_log(char *msg)
{
    if(log_file == ((void *)0))
    {
        log_file = fopen(LOG_FILE_NAME,"w");
        if(log_file == ((void *)0))
        {
            printf("\n\nCan't open log file\n\n");
            exit(0);
        }
    }
    fprintf(log_file,"%s\n",msg);
    fflush(stdout);
}

variable_types:
msg
char *


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

do
result = wgetch(stdscr);
while ( result == -1 );
return result;
}

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

do
result = wgetch(stdscr);
while ( result == -1 );
return result;
}

original_code:
int con_getch(void)
{
    int i;
    while( ( i = wgetch(stdscr) ) == (-1) );
    return i;
}

canonical_original_code:
int con_getch()
{
    int i;
    while( ( i = wgetch(stdscr) ) == (-1) );
    return i;
}


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

nodelay(stdscr, 1);
v0 = wgetch(stdscr);
if ( v0 == -1 )
v0 = 0;
nodelay(stdscr, 0);
return v0;
}

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

nodelay(stdscr, 1);
v0 = wgetch(stdscr);
if ( v0 == -1 )
v0 = 0;
nodelay(stdscr, 0);
return v0;
}

original_code:
char con_kbhit()
{
    int i, g;
    nodelay(stdscr, 1);
    i = ( ( g = wgetch(stdscr) ) == (-1) ? 0 : g );
    nodelay(stdscr, 0);
    return i;
}

canonical_original_code:
char con_kbhit()
{
    int i; int g;
    nodelay(stdscr, 1);
    i = ( ( g = wgetch(stdscr) ) == (-1) ? 0 : g );
    nodelay(stdscr, 0);
    return i;
}

variable_types: g int


decompiled_code:
__int64 __fastcall con_scanf(char *a1, __int64 a2)
{
unsigned int v2; // er12

echo();
v2 = scanw(a1, a2);
wrefresh(stdscr);
noecho();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, __int64 a2)
{
unsigned int v2; // er12

echo();
v2 = scanw(a1, a2);
wrefresh(stdscr);
noecho();
return v2;
}

original_code:
int con_scanf(char *fmt, void *app)
{
    int i;
    echo();
    i = scanw(fmt,app);
    wrefresh(stdscr);
    noecho();
    return i;
}

variable_types:
fmt
char *

variable_types:
app
void *


decompiled_code:
__int64 con_printf(char *a1, ...)
{
unsigned int v1; // er12
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = vwprintw(stdscr, a1, va);
wrefresh(stdscr);
return v1;
}

canonical_decompiled_code:
__int64 func6(char *a1, ...)
{
unsigned int v1; // er12
gcc_va_list va; // [rsp+8h] [rbp-E0h] BYREF

va_start(va, a1);
v1 = vwprintw(stdscr, a1, va);
wrefresh(stdscr);
return v1;
}

original_code:
int con_printf(char *fmt,...)
{
    va_list marker;
    int i;
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}

canonical_original_code:
int con_printf(char *fmt, ...)
{
    __builtin_va_list marker;
    int i;
    __builtin_va_start(marker,fmt);
    i = vwprintw(stdscr,fmt,marker);
    __builtin_va_end(marker);
    wrefresh(stdscr);
    return i;
}