setup

decompiled_code:
__int64 setup()
{
unsigned int i; // ebx
__int64 v1; // rax
unsigned int *v2; // rbp
__int64 result; // rax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

msg_setup = font_create_texture("Setup");
if ( msg_setup )
{
msg_instr1 = font_create_texture("Please follow the on-screen instructions");
if ( msg_setup )
{
msg_instr2 = font_create_texture("in order to set up your installation");
if ( msg_setup )
{
msg_press = font_create_texture("Please press the control for: ");
if ( msg_setup )
{
ogl_clear();
sdl_swap();
event_flush();
SDL_Delay(500LL);
for ( i = 1; i != 8; ++i )
{
v1 = event_name(i);
v2 = (unsigned int *)font_create_texture(v1);
ogl_clear();
setup_draw_msg((unsigned int *)msg_setup, 1.0, 0.012);
setup_draw_msg((unsigned int *)msg_instr1, 0.2, 0.0049999999);
setup_draw_msg((unsigned int *)msg_instr2, -0.1, 0.0049999999);
setup_draw_msg((unsigned int *)msg_press, -0.5, 0.0049999999);
setup_draw_msg(v2, -0.80000001, 0.0049999999);
sdl_swap();
event_flush();
while ( (unsigned int)event_probe(100LL, v4) != 1 )
;
event_set(i, v4);
ogl_free_texture(v2);
}
ogl_free_texture(msg_setup);
ogl_free_texture(msg_instr1);
ogl_free_texture(msg_instr2);
ogl_free_texture(msg_press);
result = 0LL;
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "Please press the control for: ");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "in order to set up your installation");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "Please follow the on-screen instructions");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "Setup");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int i; // ebx
__int64 v1; // rax
unsigned int *v2; // rbp
__int64 result; // rax
_BYTE v4[56]; // [rsp+0h] [rbp-38h] BYREF

msg_setup = font_create_texture("Setup");
if ( msg_setup )
{
msg_instr1 = font_create_texture("Please follow the on-screen instructions");
if ( msg_setup )
{
msg_instr2 = font_create_texture("in order to set up your installation");
if ( msg_setup )
{
msg_press = font_create_texture("Please press the control for: ");
if ( msg_setup )
{
ogl_clear();
sdl_swap();
event_flush();
SDL_Delay(500LL);
for ( i = 1; i != 8; ++i )
{
v1 = event_name(i);
v2 = (unsigned int *)font_create_texture(v1);
ogl_clear();
func0((unsigned int *)msg_setup, 1.0, 0.012);
func0((unsigned int *)msg_instr1, 0.2, 0.0049999999);
func0((unsigned int *)msg_instr2, -0.1, 0.0049999999);
func0((unsigned int *)msg_press, -0.5, 0.0049999999);
func0(v2, -0.80000001, 0.0049999999);
sdl_swap();
event_flush();
while ( (unsigned int)event_probe(100LL, v4) != 1 )
;
event_set(i, v4);
ogl_free_texture(v2);
}
ogl_free_texture(msg_setup);
ogl_free_texture(msg_instr1);
ogl_free_texture(msg_instr2);
ogl_free_texture(msg_press);
result = 0LL;
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "Please press the control for: ");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "in order to set up your installation");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "Please follow the on-screen instructions");
result = 0xFFFFFFFFLL;
}
}
else
{
fprintf(stderr, "Error: Couldn't create message for string '%s'", "Setup");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int setup( void ) {
 struct texture *msg_event = ((void *)0);
 struct event event;
 int i;
 msg_setup = font_create_texture( str_setup );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_setup );
  return -1;
 }
 msg_instr1 = font_create_texture( str_instr1 );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_instr1 );
  return -1;
 }
 msg_instr2 = font_create_texture( str_instr2 );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_instr2 );
  return -1;
 }
 msg_press = font_create_texture( str_press );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_press );
  return -1;
 }
 ogl_clear();
 sdl_swap();
 event_flush();
 SDL_Delay( 500 );
 for( i = 1 ; i < NUM_EVENTS ; i++ ) {
  msg_event = font_create_texture( event_name(i) );
  ogl_clear();
  setup_draw_msg( msg_setup, 1.0, 0.012 );
  setup_draw_msg( msg_instr1, 0.2, 0.005 );
  setup_draw_msg( msg_instr2, -0.1, 0.005 );
  setup_draw_msg( msg_press, -0.5, 0.005 );
  setup_draw_msg( msg_event, -0.8, 0.005 );
  sdl_swap();
  event_flush();
  while( event_probe( 100, &event ) != 1 );
  event_set( i, &event );
  ogl_free_texture( msg_event );
 }
 ogl_free_texture( msg_setup );
 ogl_free_texture( msg_instr1 );
 ogl_free_texture( msg_instr2 );
 ogl_free_texture( msg_press );
 return 0;
}

canonical_original_code:
int setup() {
 struct texture *msg_event = ((void *)0);
 struct event event;
 int i;
 msg_setup = font_create_texture( str_setup );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_setup );
  return -1;
 }
 msg_instr1 = font_create_texture( str_instr1 );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_instr1 );
  return -1;
 }
 msg_instr2 = font_create_texture( str_instr2 );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_instr2 );
  return -1;
 }
 msg_press = font_create_texture( str_press );
 if( msg_setup == ((void *)0) ) {
  fprintf( stderr, "Error: Couldn't create message for string '%s'", str_press );
  return -1;
 }
 ogl_clear();
 sdl_swap();
 event_flush();
 SDL_Delay( 500 );
 for( i = 1 ; i < NUM_EVENTS ; i++ ) {
  msg_event = font_create_texture( event_name(i) );
  ogl_clear();
  setup_draw_msg( msg_setup, 1.0, 0.012 );
  setup_draw_msg( msg_instr1, 0.2, 0.005 );
  setup_draw_msg( msg_instr2, -0.1, 0.005 );
  setup_draw_msg( msg_press, -0.5, 0.005 );
  setup_draw_msg( msg_event, -0.8, 0.005 );
  sdl_swap();
  event_flush();
  while( event_probe( 100, &event ) != 1 );
  event_set( i, &event );
  ogl_free_texture( msg_event );
 }
 ogl_free_texture( msg_setup );
 ogl_free_texture( msg_instr1 );
 ogl_free_texture( msg_instr2 );
 ogl_free_texture( msg_press );
 return 0;
}

variable_types: struct event { int device_type; int device_id; int control_type; int control_id; int value; }

variable_types: i int

user_defined_types: struct texture { unsigned int id; int width; int height; }


repo: tuxme/tuxbrio

decompiled_code:
int __fastcall lookup_match(char *s1, char *s2)
{
char *v2; // rbx
int result; // eax
char v4; // al
char *i; // rbp
char v6; // dl

if ( !s1 )
return 0;
v2 = s2;
if ( !s2 )
return 0;
result = strcmp(s1, s2);
if ( result )
{
v4 = *s1;
for ( i = s1; *i; v4 = *i )
{
v6 = *v2;
if ( !*v2 )
break;
if ( v4 == 42 )
{
if ( i[1] == v6 || !strncasecmp(i + 1, v2, 1uLL) )
++i;
else
++v2;
}
else
{
if ( v6 != v4 && strncasecmp(i, v2, 1uLL) )
return -1;
++i;
++v2;
}
}
result = -(i != &s1[strlen(s1) - 1]);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s1, char *s2)
{
char *v2; // rbx
int result; // eax
char v4; // al
char *i; // rbp
char v6; // dl

if ( !s1 )
return 0;
v2 = s2;
if ( !s2 )
return 0;
result = strcmp(s1, s2);
if ( result )
{
v4 = *s1;
for ( i = s1; *i; v4 = *i )
{
v6 = *v2;
if ( !*v2 )
break;
if ( v4 == 42 )
{
if ( i[1] == v6 || !strncasecmp(i + 1, v2, 1uLL) )
++i;
else
++v2;
}
else
{
if ( v6 != v4 && strncasecmp(i, v2, 1uLL) )
return -1;
++i;
++v2;
}
}
result = -(i != &s1[strlen(s1) - 1]);
}
return result;
}

original_code:
int lookup_match( const char *pattern, const char *value ) {
 if( !(pattern && value) )
  return 0;
 if( strcmp( pattern, value ) == 0 ) {
  return 0;
 }
 else {
  char *ppos = (char*)pattern;
  char *vpos = (char*)value;
  while( *ppos && *vpos ) {
   if( *ppos == '*' ) {
    if( *vpos == *(ppos+1) || strncasecmp( ppos+1, vpos, 1 ) == 0 )
     ppos++;
    else
     vpos++;
   }
   else if( *vpos == *ppos || strncasecmp( ppos, vpos, 1 ) == 0 ) {
    ppos++;
    vpos++;
   }
   else {
    return -1;
   }
  }
  if( ppos == pattern + strlen(pattern) - 1 ) {
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int lookup_match(char *pattern, char *value) {
 if( !(pattern && value) )
  return 0;
 if( strcmp( pattern, value ) == 0 ) {
  return 0;
 }
 else {
  char *ppos = (char*)pattern;
  char *vpos = (char*)value;
  while( *ppos && *vpos ) {
   if( *ppos == '*' ) {
    if( *vpos == *(ppos+1) || strncasecmp( ppos+1, vpos, 1 ) == 0 )
     ppos++;
    else
     vpos++;
   }
   else if( *vpos == *ppos || strncasecmp( ppos, vpos, 1 ) == 0 ) {
    ppos++;
    vpos++;
   }
   else {
    return -1;
   }
  }
  if( ppos == pattern + strlen(pattern) - 1 ) {
   return 0;
  }
 }
 return -1;
}

variable_types:
pattern
char *

variable_types:
value
char *

variable_types:
ppos
char *

variable_types:
vpos
char *

return_type: int


decompiled_code:
char *__fastcall lookup_category(__int64 a1, char *a2)
{
char *v2; // rbp
char *v3; // rbx

v2 = a2;
v3 = *(char **)(a1 + 152);
if ( v3 )
{
while ( lookup_match(v3 + 8, a2) )
{
v3 = *(char **)v3;
if ( !v3 )
return v2;
}
v2 = v3 + 40;
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(__int64 a1, char *a2)
{
char *v2; // rbp
char *v3; // rbx

v2 = a2;
v3 = *(char **)(a1 + 152);
if ( v3 )
{
while ( func0(v3 + 8, a2) )
{
v3 = *(char **)v3;
if ( !v3 )
return v2;
}
v2 = v3 + 40;
}
return v2;
}

original_code:
const char *lookup_category( struct config_category *category, const char *value ) {
 char *display_name = ((void *)0);
 struct config_lookup *lookup = category->lookups;
 while( lookup ) {
  if( lookup_match( lookup->match, value ) == 0 ) {
   display_name = lookup->value;
   break;
  }
  lookup = lookup->next;
 }
 if( display_name )
  return display_name;
 else
  return value;
}

canonical_original_code:
char *lookup_category(struct config_category *category, char *value) {
 char *display_name = ((void *)0);
 struct config_lookup *lookup = category->lookups;
 while( lookup ) {
  if( lookup_match( lookup->match, value ) == 0 ) {
   display_name = lookup->value;
   break;
  }
  lookup = lookup->next;
 }
 if( display_name )
  return display_name;
 else
  return value;
}

variable_types: struct config_category { struct config_category *next; int id; char name[128]; struct config_category_value { struct config_category_value *next; char name[128]; } *values; struct config_lookup { struct config_lookup *next; char match[32]; char value[32]; } *lookups; } *

return_type: char *

user_defined_types: struct config_category { struct config_category *next; int id; char name[128]; struct config_category_value *values; struct config_lookup *lookups; }


decompiled_code:
__int64 sdl_init()
{
_DWORD *v0; // rbx
const __m128i *v1; // rax
__int64 result; // rax
const char *v3; // rax
const char *v4; // rax

v0 = (_DWORD *)config_get();
if ( (int)SDL_Init(0xFFFFLL) < 0 )
{
v3 = (const char *)SDL_GetError();
fprintf(stderr, "Error: Unable to initialise SDL: %s\n", v3);
result = 1LL;
}
else
{
SDL_ShowCursor(0LL);
v1 = (const __m128i *)SDL_GetVideoInfo();
saved_video = (__int128)_mm_loadu_si128(v1);
qword_270 = v1[1].m128i_i64[0];
SDL_GL_SetAttribute(5LL, 1LL);
if ( SDL_SetVideoMode((unsigned int)v0[17], (unsigned int)v0[18], 32LL, v0[16] == 0 ? 2 : -2147483646) )
{
SDL_initFramerate(&manager);
if ( (int)v0[22] < 0 )
{
frame_rate = 0;
fwrite("Warning: Negative frame rate, setting to 0 (unlimited)\n", 1uLL, 0x37uLL, stderr);
}
else
{
frame_rate = v0[22];
}
if ( frame_rate > 100 )
{
frame_rate = 100;
fprintf(stderr, "Warning: Frame rate above maximum allowed (%d) setting to maximum\n", 100LL);
}
if ( frame_rate )
SDL_setFramerate(&manager);
SDL_WM_SetCaption("Cabrio", 0LL);
result = 0LL;
}
else
{
v4 = (const char *)SDL_GetError();
fprintf(stderr, "Error: Unable to set video mode: %s\n", v4);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
_DWORD *v0; // rbx
const __m128i *v1; // rax
__int64 result; // rax
const char *v3; // rax
const char *v4; // rax

v0 = (_DWORD *)config_get();
if ( (int)SDL_Init(0xFFFFLL) < 0 )
{
v3 = (const char *)SDL_GetError();
fprintf(stderr, "Error: Unable to initialise SDL: %s\n", v3);
result = 1LL;
}
else
{
SDL_ShowCursor(0LL);
v1 = (const __m128i *)SDL_GetVideoInfo();
saved_video = (__int128)_mm_loadu_si128(v1);
qword_270 = v1[1].m128i_i64[0];
SDL_GL_SetAttribute(5LL, 1LL);
if ( SDL_SetVideoMode((unsigned int)v0[17], (unsigned int)v0[18], 32LL, v0[16] == 0 ? 2 : -2147483646) )
{
SDL_initFramerate(&manager);
if ( (int)v0[22] < 0 )
{
frame_rate = 0;
fwrite("Warning: Negative frame rate, setting to 0 (unlimited)\n", 1uLL, 0x37uLL, stderr);
}
else
{
frame_rate = v0[22];
}
if ( frame_rate > 100 )
{
frame_rate = 100;
fprintf(stderr, "Warning: Frame rate above maximum allowed (%d) setting to maximum\n", 100LL);
}
if ( frame_rate )
SDL_setFramerate(&manager);
SDL_WM_SetCaption("Cabrio", 0LL);
result = 0LL;
}
else
{
v4 = (const char *)SDL_GetError();
fprintf(stderr, "Error: Unable to set video mode: %s\n", v4);
result = 1LL;
}
}
return result;
}

original_code:
int sdl_init( void ) {
 int mode = 0x00000000|0x00000002;
 const struct config *config = config_get();
 if( SDL_Init(0x0000FFFF) < 0 ) {
  fprintf(stderr, "Error: Unable to initialise SDL: %s\n", SDL_GetError());
  return 1;
 }
 SDL_ShowCursor(0);
 memcpy( &saved_video, SDL_GetVideoInfo(), sizeof(SDL_VideoInfo) );
 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
 if( config->iface.full_screen )
  mode |= 0x80000000;
 screen = SDL_SetVideoMode( config->iface.screen_width, config->iface.screen_height, SDL_SCREEN_BPP, mode );
 if( screen == ((void *)0) ) {
  fprintf(stderr, "Error: Unable to set video mode: %s\n", SDL_GetError());
  return 1;
 }
 SDL_initFramerate( &manager );
 frame_rate = config->iface.frame_rate;
 if( frame_rate < 0 ) {
  frame_rate = 0;
  fprintf( stderr, "Warning: Negative frame rate, setting to 0 (unlimited)\n" );
 }
 if( frame_rate > MAX_FRAME_RATE ) {
  frame_rate = MAX_FRAME_RATE;
  fprintf( stderr, "Warning: Frame rate above maximum allowed (%d) setting to maximum\n", MAX_FRAME_RATE );
 }
 if( frame_rate ) {
  SDL_setFramerate( &manager, frame_rate );
 }
 SDL_WM_SetCaption( title, ((void *)0) );
 return 0;
}

canonical_original_code:
int sdl_init() {
 int mode = 0x00000000|0x00000002;
 struct config *config = config_get();
 if( SDL_Init(0x0000FFFF) < 0 ) {
  fprintf(stderr, "Error: Unable to initialise SDL: %s\n", SDL_GetError());
  return 1;
 }
 SDL_ShowCursor(0);
 memcpy( &saved_video, SDL_GetVideoInfo(), sizeof(SDL_VideoInfo) );
 SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
 if( config->iface.full_screen )
  mode |= 0x80000000;
 screen = SDL_SetVideoMode( config->iface.screen_width, config->iface.screen_height, SDL_SCREEN_BPP, mode );
 if( screen == ((void *)0) ) {
  fprintf(stderr, "Error: Unable to set video mode: %s\n", SDL_GetError());
  return 1;
 }
 SDL_initFramerate( &manager );
 frame_rate = config->iface.frame_rate;
 if( frame_rate < 0 ) {
  frame_rate = 0;
  fprintf( stderr, "Warning: Negative frame rate, setting to 0 (unlimited)\n" );
 }
 if( frame_rate > MAX_FRAME_RATE ) {
  frame_rate = MAX_FRAME_RATE;
  fprintf( stderr, "Warning: Frame rate above maximum allowed (%d) setting to maximum\n", MAX_FRAME_RATE );
 }
 if( frame_rate ) {
  SDL_setFramerate( &manager, frame_rate );
 }
 SDL_WM_SetCaption( title, ((void *)0) );
 return 0;
}

variable_types: mode int

variable_types: struct config { struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param { struct config_param *next; char name[64]; char value[64]; } *params; struct config_platform { struct config_platform *next; char name[128]; } *platform; } *emulators; struct config_platform *platforms; struct config_category { struct config_category *next; int id; char name[128]; struct config_category_value { struct config_category_value *next; char name[128]; } *values; struct config_lookup { struct config_lookup *next; char match[32]; char value[32]; } *lookups; } *categories; struct config_game { struct config_game *next; char name[128]; char rom_image[256]; char video[256]; char emulator[128]; struct config_game_category { struct config_game_category *next; struct config_category *category; struct config_category_value *value; } *categories; struct config_param *params; struct config_platform *platform; struct config_image { struct config_image *next; struct config_image_type { struct config_image_type *next; char name[128]; } *type; char file_name[256]; } *images; } *games; struct config_theme { struct config_theme *next; char name[128]; char directory[256]; char background_image[256]; int background_rotation; int background_transparency; char sounds[-1][256]; char font_file[256]; int font_size; struct config_rgb { unsigned char red; unsigned char green; unsigned char blue; } font_rgb; struct config_menu { char texture[256]; float item_width; float item_height; float font_scale; float zoom; int transparency; float offset1; float offset2; int max_visible; float spacing; int orientation; int auto_hide; int border; } menu; struct config_submenu { char texture[256]; float item_width; float item_height; float font_scale; float offset1; float offset2; } submenu; struct config_game_sel { float offset1; float offset2; float size_x; float size_y; float tile_size; int orientation; int selected; struct config_game_sel_tile { struct config_game_sel_tile *next; int order; float pos[3]; float angle[3]; int transparency; } *tiles; } game_sel; struct config_snap { float offset1; float offset2; float angle_x; float angle_y; float angle_z; float size; int fix_aspect_ratio; int auto_hide; int platform_icons; } snap; struct config_hints { float offset1; float offset2; float size; float spacing; int pulse; char image_back[256]; char image_select[256]; char image_arrow[256]; } hints; } *themes; struct config_image_type *image_types; struct config_location { struct config_location *next; struct config_location_type { struct config_location_type *next; char name[128]; } *type; char directory[256]; } *locations; struct config_location_type *location_types; struct config_iface { int full_screen; int screen_width; int screen_height; int screen_rotation; int screen_hflip; int screen_vflip; int frame_rate; int gfx_quality; int gfx_max_width; int gfx_max_height; int prune_menus; struct config_labels { char label_all[32]; char label_platform[32]; char label_back[32]; char label_select[32]; char label_lists[32]; } labels; struct config_control { int device_type; int device_id; int control_type; int control_id; int value; } controls[-1]; char theme_name[128]; struct config_theme theme; } iface; } *

user_defined_types: struct config { struct config_emulator *emulators; struct config_platform *platforms; struct config_category *categories; struct config_game *games; struct config_theme *themes; struct config_image_type *image_types; struct config_location *locations; struct config_location_type *location_types; struct config_iface iface; }

user_defined_types: struct config_iface { int full_screen; int screen_width; int screen_height; int screen_rotation; int screen_hflip; int screen_vflip; int frame_rate; int gfx_quality; int gfx_max_width; int gfx_max_height; int prune_menus; struct config_labels labels; struct config_control controls[-1]; char theme_name[128]; struct config_theme theme; }

user_defined_types: struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform *platform; }

user_defined_types: struct config_game { struct config_game *next; char name[128]; char rom_image[256]; char video[256]; char emulator[128]; struct config_game_category *categories; struct config_param *params; struct config_platform *platform; struct config_image *images; }

user_defined_types: struct config_theme { struct config_theme *next; char name[128]; char directory[256]; char background_image[256]; int background_rotation; int background_transparency; char sounds[-1][256]; char font_file[256]; int font_size; struct config_rgb font_rgb; struct config_menu menu; struct config_submenu submenu; struct config_game_sel game_sel; struct config_snap snap; struct config_hints hints; }

user_defined_types: struct config_location { struct config_location *next; struct config_location_type *type; char directory[256]; }

user_defined_types: struct config_game_sel { float offset1; float offset2; float size_x; float size_y; float tile_size; int orientation; int selected; struct config_game_sel_tile *tiles; }

user_defined_types: struct config_image { struct config_image *next; struct config_image_type *type; char file_name[256]; }


decompiled_code:
__int64 sdl_free()
{
if ( *(_DWORD *)(config_get() + 64) )
SDL_SetVideoMode(
(unsigned int)qword_270,
HIDWORD(qword_270),
*(unsigned __int8 *)(*((_QWORD *)&saved_video + 1) + 8LL),
0x80000000LL);
return SDL_Quit();
}

canonical_decompiled_code:
__int64 func1()
{
if ( *(_DWORD *)(config_get() + 64) )
SDL_SetVideoMode(
(unsigned int)qword_270,
HIDWORD(qword_270),
*(unsigned __int8 *)(*((_QWORD *)&saved_video + 1) + 8LL),
0x80000000LL);
return SDL_Quit();
}

original_code:
void sdl_free( void ) {
 if( config_get()->iface.full_screen )
  SDL_SetVideoMode( saved_video.current_w, saved_video.current_h, saved_video.vfmt->BitsPerPixel, 0x80000000 );
 SDL_Quit();
}

canonical_original_code:
void sdl_free() {
 if( config_get()->iface.full_screen )
  SDL_SetVideoMode( saved_video.current_w, saved_video.current_h, saved_video.vfmt->BitsPerPixel, 0x80000000 );
 SDL_Quit();
}

return_type: void


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

if ( frame_rate )
result = SDL_framerateDelay(&manager);
return result;
}

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

if ( frame_rate )
result = SDL_framerateDelay(&manager);
return result;
}

original_code:
void sdl_frame_delay( void ) {
 if( frame_rate ) {
  SDL_framerateDelay( &manager );
 }
}

canonical_original_code:
void sdl_frame_delay() {
 if( frame_rate ) {
  SDL_framerateDelay( &manager );
 }
}


decompiled_code:
__int64 sdl_swap()
{
return SDL_GL_SwapBuffers();
}

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

original_code:
void sdl_swap( void ) {
 SDL_GL_SwapBuffers();
}

canonical_original_code:
void sdl_swap() {
 SDL_GL_SwapBuffers();
}


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

if ( a1 == 4 )
return 2LL;
if ( a1 > 4 )
{
result = 3LL;
if ( a1 != 8 )
{
LABEL_8:
fprintf(stderr, "Warning: Bogus hat direction %d\n", (unsigned int)a1);
return 0LL;
}
}
else
{
result = (unsigned int)a1;
if ( a1 != 1 )
{
if ( a1 == 2 )
return 4LL;
goto LABEL_8;
}
}
return result;
}

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

if ( a1 == 4 )
return 2LL;
if ( a1 > 4 )
{
result = 3LL;
if ( a1 != 8 )
{
LABEL_8:
fprintf(stderr, "Warning: Bogus hat direction %d\n", (unsigned int)a1);
return 0LL;
}
}
else
{
result = (unsigned int)a1;
if ( a1 != 1 )
{
if ( a1 == 2 )
return 4LL;
goto LABEL_8;
}
}
return result;
}

original_code:
int sdl_hat_dir_value( int direction ) {
 switch( direction ) {
  case 0x01:
   return DIR_UP;
   break;
  case 0x04:
   return DIR_DOWN;
   break;
  case 0x08:
   return DIR_LEFT;
   break;
  case 0x02:
   return DIR_RIGHT;
   break;
  default:
   fprintf( stderr, "Warning: Bogus hat direction %d\n", direction );
   break;
 }
 return 0;
}

canonical_original_code:
int sdl_hat_dir_value(int direction) {
 switch( direction ) {
  case 0x01:
   return DIR_UP;
   break;
  case 0x04:
   return DIR_DOWN;
   break;
  case 0x08:
   return DIR_LEFT;
   break;
  case 0x02:
   return DIR_RIGHT;
   break;
  default:
   fprintf( stderr, "Warning: Bogus hat direction %d\n", direction );
   break;
 }
 return 0;
}

variable_types: direction int


decompiled_code:
__int64 ogl_screen_width()
{
return (unsigned int)width;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)width;
}

original_code:
int ogl_screen_width( void ) {
 return width;
}

canonical_original_code:
int ogl_screen_width() {
 return width;
}


decompiled_code:
__int64 ogl_screen_height()
{
return (unsigned int)height;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)height;
}

original_code:
int ogl_screen_height( void ) {
 return height;
}

canonical_original_code:
int ogl_screen_height() {
 return height;
}


decompiled_code:
_BOOL8 ogl_screen_orientation()
{
return height > width;
}

canonical_decompiled_code:
_BOOL8 func5()
{
return height > width;
}

original_code:
int ogl_screen_orientation( void ) {
 if( height > width )
  return CONFIG_PORTRAIT;
 else
  return CONFIG_LANDSCAPE;
}

canonical_original_code:
int ogl_screen_orientation() {
 if( height > width )
  return CONFIG_PORTRAIT;
 else
  return CONFIG_LANDSCAPE;
}


decompiled_code:
__int64 __fastcall ogl_screen_rotate(int a1)
{
int v1; // ebx
__int64 result; // rax

v1 = -a1;
if ( -a1 % 90 )
{
v1 -= -a1 % 90;
fwrite("Warning: Screen rotation rounded down to nearest 90 degrees\n", 1uLL, 0x3CuLL, stderr);
}
if ( rotation != 180 * (rotation / 180) )
{
result = (unsigned int)(180 * (v1 / 180));
if ( v1 != (_DWORD)result )
goto LABEL_6;
goto LABEL_5;
}
result = (unsigned int)(180 * (v1 / 180));
if ( v1 != (_DWORD)result )
{
LABEL_5:
result = (unsigned int)width;
width = height;
height = result;
}
LABEL_6:
rotation = v1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // ebx
__int64 result; // rax

v1 = -a1;
if ( -a1 % 90 )
{
v1 -= -a1 % 90;
fwrite("Warning: Screen rotation rounded down to nearest 90 degrees\n", 1uLL, 0x3CuLL, stderr);
}
if ( rotation != 180 * (rotation / 180) )
{
result = (unsigned int)(180 * (v1 / 180));
if ( v1 != (_DWORD)result )
goto LABEL_6;
goto LABEL_5;
}
result = (unsigned int)(180 * (v1 / 180));
if ( v1 != (_DWORD)result )
{
LABEL_5:
result = (unsigned int)width;
width = height;
height = result;
}
LABEL_6:
rotation = v1;
return result;
}

original_code:
void ogl_screen_rotate( int angle ) {
 int tmp = -angle;
 if( tmp % 90 != 0 ) {
  tmp -= (tmp % 90);
  fprintf( stderr, "Warning: Screen rotation rounded down to nearest 90 degrees\n" );
 }
 if( (rotation % 180 == 0 && tmp % 180 != 0)
 || (rotation % 180 != 0 && tmp % 180 == 0) ) {
  int swap = width;
  width = height;
  height = swap;
 }
 rotation = tmp;
}

canonical_original_code:
void ogl_screen_rotate(int angle) {
 int tmp = -angle;
 if( tmp % 90 != 0 ) {
  tmp -= (tmp % 90);
  fprintf( stderr, "Warning: Screen rotation rounded down to nearest 90 degrees\n" );
 }
 if( (rotation % 180 == 0 && tmp % 180 != 0)
 || (rotation % 180 != 0 && tmp % 180 == 0) ) {
  int swap = width;
  width = height;
  height = swap;
 }
 rotation = tmp;
}

variable_types: angle int

variable_types: tmp int

variable_types: swap int


decompiled_code:
__int64 ogl_load_alterego()
{
glLoadIdentity();
glRotatef((float)rotation, 0.0, 0.0, 1.0);
return glScalef(*(float *)&xscale, *(float *)&yscale, 1.0);
}

canonical_decompiled_code:
__int64 func7()
{
glLoadIdentity();
glRotatef((float)rotation, 0.0, 0.0, 1.0);
return glScalef(*(float *)&xscale, *(float *)&yscale, 1.0);
}

original_code:
void ogl_load_alterego( void ) {
 glLoadIdentity();
 glRotatef( (GLfloat)rotation, 0.0, 0.0, 1.0 );
 glScalef( xscale, yscale, 1.0 );
}

canonical_original_code:
void ogl_load_alterego() {
 glLoadIdentity();
 glRotatef( (float)rotation, 0.0, 0.0, 1.0 );
 glScalef( xscale, yscale, 1.0 );
}


decompiled_code:
__int64 ogl_init()
{
int *v0; // rbx
const char *v1; // rdi
unsigned int v2; // eax
const char *v4; // rax

v0 = (int *)config_get();
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(3553LL);
glShadeModel(7425LL);
glClearDepth(1.0);
glEnable(2929LL);
glDepthFunc(515LL);
glEnable(3042LL);
if ( v0[23] > 0 )
glHint(3152LL, 4354LL);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(45.0, (float)((float)v0[17] / (float)v0[18]), 0.1, 100.0);
glMatrixMode(5888LL);
width = v0[17];
height = v0[18];
if ( v0[20] )
yscale ^= LC7;
if ( v0[21] )
xscale ^= LC7;
ogl_screen_rotate(v0[19]);
ogl_load_alterego();
v1 = (const char *)glGetString(7939LL);
if ( strstr(v1, "GL_ARB_texture_non_power_of_two") )
nopt_textures = 1;
v2 = glGetError();
if ( !v2 )
return 0LL;
v4 = (const char *)gluErrorString(v2);
fprintf(stderr, "Error: couldn't initialise OpenGL: %s\n", v4);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func8()
{
int *v0; // rbx
const char *v1; // rdi
unsigned int v2; // eax
const char *v4; // rax

v0 = (int *)config_get();
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 1.0);
glEnable(3553LL);
glShadeModel(7425LL);
glClearDepth(1.0);
glEnable(2929LL);
glDepthFunc(515LL);
glEnable(3042LL);
if ( v0[23] > 0 )
glHint(3152LL, 4354LL);
glMatrixMode(5889LL);
glLoadIdentity();
gluPerspective(45.0, (float)((float)v0[17] / (float)v0[18]), 0.1, 100.0);
glMatrixMode(5888LL);
width = v0[17];
height = v0[18];
if ( v0[20] )
yscale ^= LC7;
if ( v0[21] )
xscale ^= LC7;
func6(v0[19]);
func7();
v1 = (const char *)glGetString(7939LL);
if ( strstr(v1, "GL_ARB_texture_non_power_of_two") )
nopt_textures = 1;
v2 = glGetError();
if ( !v2 )
return 0LL;
v4 = (const char *)gluErrorString(v2);
fprintf(stderr, "Error: couldn't initialise OpenGL: %s\n", v4);
return 0xFFFFFFFFLL;
}

original_code:
int ogl_init( void ) {
 const struct config *config = config_get();
 GLenum error = 0;
 glLoadIdentity();
 glClearColor( 0, 0, 0, 1.0 );
 glEnable( 0x0DE1 );
 glShadeModel( 0x1D01 );
 glClearDepth( 1.0 );
 glEnable( 0x0B71 );
 glDepthFunc( 0x0203 );
 glEnable( 0x0BE2 );
 if( config->iface.gfx_quality > CONFIG_LOW )
  glHint( 0x0C50, 0x1102 );
 glMatrixMode( 0x1701 );
 glLoadIdentity();
 gluPerspective( 45.0, (GLfloat)config->iface.screen_width/(GLfloat)config->iface.screen_height, 0.1, 100.0 );
 glMatrixMode( 0x1700 );
 width = config->iface.screen_width;
 height = config->iface.screen_height;
 if( config->iface.screen_hflip )
  yscale = -yscale;
 if( config->iface.screen_vflip )
  xscale = -xscale;
 ogl_screen_rotate( config->iface.screen_rotation );
 ogl_load_alterego();
 if( strstr( (char*)glGetString(0x1F03), "GL_ARB_texture_non_power_of_two" ) != ((void *)0) )
  nopt_textures = 1;
 error = glGetError();
 if( error == 0 ) {
  return 0;
 }
 else {
  fprintf(stderr, "Error: couldn't initialise OpenGL: %s\n", gluErrorString(error) );
  return -1;
 }
}

canonical_original_code:
int ogl_init() {
 struct config *config = config_get();
 unsigned int error = 0;
 glLoadIdentity();
 glClearColor( 0, 0, 0, 1.0 );
 glEnable( 0x0DE1 );
 glShadeModel( 0x1D01 );
 glClearDepth( 1.0 );
 glEnable( 0x0B71 );
 glDepthFunc( 0x0203 );
 glEnable( 0x0BE2 );
 if( config->iface.gfx_quality > CONFIG_LOW )
  glHint( 0x0C50, 0x1102 );
 glMatrixMode( 0x1701 );
 glLoadIdentity();
 gluPerspective( 45.0, (float)config->iface.screen_width/(float)config->iface.screen_height, 0.1, 100.0 );
 glMatrixMode( 0x1700 );
 width = config->iface.screen_width;
 height = config->iface.screen_height;
 if( config->iface.screen_hflip )
  yscale = -yscale;
 if( config->iface.screen_vflip )
  xscale = -xscale;
 ogl_screen_rotate( config->iface.screen_rotation );
 ogl_load_alterego();
 if( strstr( (char *)glGetString(0x1F03), "GL_ARB_texture_non_power_of_two" ) != ((void *)0) )
  nopt_textures = 1;
 error = glGetError();
 if( error == 0 ) {
  return 0;
 }
 else {
  fprintf(stderr, "Error: couldn't initialise OpenGL: %s\n", gluErrorString(error) );
  return -1;
 }
}

variable_types:
error
unsigned int

user_defined_types: struct config_labels { char label_all[32]; char label_platform[32]; char label_back[32]; char label_select[32]; char label_lists[32]; }

user_defined_types: struct config_rgb { unsigned char red; unsigned char green; unsigned char blue; }

user_defined_types: struct config_menu { char texture[256]; float item_width; float item_height; float font_scale; float zoom; int transparency; float offset1; float offset2; int max_visible; float spacing; int orientation; int auto_hide; int border; }

user_defined_types: struct config_submenu { char texture[256]; float item_width; float item_height; float font_scale; float offset1; float offset2; }

user_defined_types: struct config_snap { float offset1; float offset2; float angle_x; float angle_y; float angle_z; float size; int fix_aspect_ratio; int auto_hide; int platform_icons; }

user_defined_types: struct config_hints { float offset1; float offset2; float size; float spacing; int pulse; char image_back[256]; char image_select[256]; char image_arrow[256]; }

user_defined_types: struct config_control { int device_type; int device_id; int control_type; int control_id; int value; }

user_defined_types: struct config_param { struct config_param *next; char name[64]; char value[64]; }

user_defined_types: struct config_platform { struct config_platform *next; char name[128]; }

user_defined_types: struct config_category_value { struct config_category_value *next; char name[128]; }

user_defined_types: struct config_lookup { struct config_lookup *next; char match[32]; char value[32]; }

user_defined_types: struct config_game_category { struct config_game_category *next; struct config_category *category; struct config_category_value *value; }

user_defined_types: struct config_location_type { struct config_location_type *next; char name[128]; }

user_defined_types: struct config_game_sel_tile { struct config_game_sel_tile *next; int order; float pos[3]; float angle[3]; int transparency; }

user_defined_types: struct config_image_type { struct config_image_type *next; char name[128]; }


decompiled_code:
_DWORD *ogl_create_empty_texture()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0xCuLL);
v1 = v0;
if ( v0 )
{
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
glGenTextures(1LL, v0);
}
return v1;
}

canonical_decompiled_code:
_DWORD *func9()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0xCuLL);
v1 = v0;
if ( v0 )
{
*(_QWORD *)v0 = 0LL;
v0[2] = 0;
glGenTextures(1LL, v0);
}
return v1;
}

original_code:
struct texture *ogl_create_empty_texture( void ) {
 struct texture *t = malloc( sizeof(struct texture) );
 if( t ) {
  memset( t, 0, sizeof(struct texture) );
  glGenTextures( 1, &t->id );
 }
 return t;
}

canonical_original_code:
struct texture *ogl_create_empty_texture() {
 struct texture *t = malloc( sizeof(struct texture) );
 if( t ) {
  memset( t, 0, sizeof(struct texture) );
  glGenTextures( 1, &t->id );
 }
 return t;
}

variable_types: struct texture { unsigned int id; int width; int height; } *


decompiled_code:
void __fastcall ogl_free_texture(void *ptr)
{
if ( ptr )
{
if ( *(_DWORD *)ptr )
glDeleteTextures(1LL, ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( ptr )
{
if ( *(_DWORD *)ptr )
glDeleteTextures(1LL, ptr);
free(ptr);
}
}

original_code:
void ogl_free_texture( struct texture *t ) {
 if( t ) {
  if( t->id )
   glDeleteTextures( 1, &t->id );
  free( t );
  t = ((void *)0);
 }
}

canonical_original_code:
void ogl_free_texture(struct texture *t) {
 if( t ) {
  if( t->id )
   glDeleteTextures( 1, &t->id );
  free( t );
  t = ((void *)0);
 }
}

user_defined_types: struct texture { unsigned int id; int width; int height; }


decompiled_code:
__int64 ogl_clear()
{
return glClear(16640LL);
}

canonical_decompiled_code:
__int64 func11()
{
return glClear(16640LL);
}

original_code:
void ogl_clear( void ) {
 glClear( 0x00004000 | 0x00000100 );
 void ogl_load_alterego();
}

canonical_original_code:
void ogl_clear() {
 glClear( 0x00004000 | 0x00000100 );
 void ogl_load_alterego();
}


decompiled_code:
__int64 ogl_flush()
{
return glFlush();
}

canonical_decompiled_code:
__int64 func12()
{
return glFlush();
}

original_code:
void ogl_flush( void ) {
 glFlush();
}

canonical_original_code:
void ogl_flush() {
 glFlush();
}


decompiled_code:
__int64 ogl_nopt_textures()
{
return (unsigned int)nopt_textures;
}

canonical_decompiled_code:
__int64 func13()
{
return (unsigned int)nopt_textures;
}

original_code:
int ogl_nopt_textures( void ) {
 return nopt_textures;
}

canonical_original_code:
int ogl_nopt_textures() {
 return nopt_textures;
}


decompiled_code:
__int64 sound_open_mixer()
{
unsigned int v0; // ebx
const char *v2; // rax

if ( mixer_open || (v0 = Mix_OpenAudio(22050LL, 32784LL, 4LL, 4096LL), v0 != -1) )
{
mixer_open = 1;
v0 = 0;
}
else
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Error: Unable to initialise sound: %s\n", v2);
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
const char *v2; // rax

if ( mixer_open || (v0 = Mix_OpenAudio(22050LL, 32784LL, 4LL, 4096LL), v0 != -1) )
{
mixer_open = 1;
v0 = 0;
}
else
{
v2 = (const char *)SDL_GetError();
fprintf(stderr, "Error: Unable to initialise sound: %s\n", v2);
}
return v0;
}

original_code:
int sound_open_mixer( void ) {
 if( !mixer_open ) {
  if( Mix_OpenAudio( 22050, 0x8010, 4, AUDIO_CHUNK_SIZE ) == -1 ) {
   fprintf( stderr, "Error: Unable to initialise sound: %s\n", SDL_GetError() );
   return -1;
  }
 }
 mixer_open = 1;
 return 0;
}

canonical_original_code:
int sound_open_mixer() {
 if( !mixer_open ) {
  if( Mix_OpenAudio( 22050, 0x8010, 4, AUDIO_CHUNK_SIZE ) == -1 ) {
   fprintf( stderr, "Error: Unable to initialise sound: %s\n", SDL_GetError() );
   return -1;
  }
 }
 mixer_open = 1;
 return 0;
}


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

if ( mixer_open )
result = Mix_CloseAudio();
mixer_open = 0;
return result;
}

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

if ( mixer_open )
result = Mix_CloseAudio();
mixer_open = 0;
return result;
}

original_code:
void sound_close_mixer( void ) {
 if( mixer_open )
  Mix_CloseAudio();
 mixer_open = 0;
}

canonical_original_code:
void sound_close_mixer() {
 if( mixer_open )
  Mix_CloseAudio();
 mixer_open = 0;
}


decompiled_code:
__int64 sound_init()
{
unsigned int v0; // er12
__int64 *v1; // rbp
__int64 i; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v7; // rax

sounds = 0LL;
qword_268 = 0LL;
qword_270 = 0LL;
qword_278 = 0LL;
if ( (unsigned int)sound_open_mixer() )
return (unsigned int)-1;
v0 = 0;
v1 = &sounds;
for ( i = 1216LL; i != 2240; i += 256LL )
{
v3 = config_get();
v4 = SDL_RWFromFile(v3 + i, "rb");
v5 = Mix_LoadWAV_RW(v4, 1LL);
*v1 = v5;
if ( !v5 )
{
v7 = config_get();
fprintf(stderr, "Warning: Unable to open sound: %s\n", (const char *)(v7 + i));
}
++v1;
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
__int64 *v1; // rbp
__int64 i; // rbx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v7; // rax

sounds = 0LL;
qword_268 = 0LL;
qword_270 = 0LL;
qword_278 = 0LL;
if ( (unsigned int)func0() )
return (unsigned int)-1;
v0 = 0;
v1 = &sounds;
for ( i = 1216LL; i != 2240; i += 256LL )
{
v3 = config_get();
v4 = SDL_RWFromFile(v3 + i, "rb");
v5 = Mix_LoadWAV_RW(v4, 1LL);
*v1 = v5;
if ( !v5 )
{
v7 = config_get();
fprintf(stderr, "Warning: Unable to open sound: %s\n", (const char *)(v7 + i));
}
++v1;
}
return v0;
}

original_code:
int sound_init( void ) {
 int i;
 for( i = 0 ; i < NUM_SOUNDS ; i++ )
  sounds[i] = ((void *)0);
 if( sound_open_mixer() != 0 )
  return -1;
 for( i = 0 ; i < NUM_SOUNDS ; i++ ) {
  sounds[i] = Mix_LoadWAV_RW(SDL_RWFromFile(config_get()->iface.theme.sounds[i], "rb"), 1);
  if( sounds[i] == ((void *)0) ) {
   fprintf( stderr, "Warning: Unable to open sound: %s\n", config_get()->iface.theme.sounds[i] );
  }
 }
 return 0;
}

canonical_original_code:
int sound_init() {
 int i;
 for( i = 0 ; i < NUM_SOUNDS ; i++ )
  sounds[i] = ((void *)0);
 if( sound_open_mixer() != 0 )
  return -1;
 for( i = 0 ; i < NUM_SOUNDS ; i++ ) {
  sounds[i] = Mix_LoadWAV_RW(SDL_RWFromFile(config_get()->iface.theme.sounds[i], "rb"), 1);
  if( sounds[i] == ((void *)0) ) {
   fprintf( stderr, "Warning: Unable to open sound: %s\n", config_get()->iface.theme.sounds[i] );
  }
 }
 return 0;
}


decompiled_code:
__int64 sound_free()
{
const char *v0; // rbx

v0 = (const char *)&sounds;
do
{
if ( *(_QWORD *)v0 )
{
Mix_FreeChunk();
*(_QWORD *)v0 = 0LL;
}
v0 += 8;
}
while ( v0 != "Error: Unable to initialise sound: %s\n" );
return sound_close_mixer();
}

canonical_decompiled_code:
__int64 func3()
{
const char *v0; // rbx

v0 = (const char *)&sounds;
do
{
if ( *(_QWORD *)v0 )
{
Mix_FreeChunk();
*(_QWORD *)v0 = 0LL;
}
v0 += 8;
}
while ( v0 != "Error: Unable to initialise sound: %s\n" );
return func1();
}

original_code:
void sound_free( void ) {
 int i;
 for( i = 0 ; i < NUM_SOUNDS ; i++ ) {
  if( sounds[i] ) {
   Mix_FreeChunk( sounds[i] );
   sounds[i] = ((void *)0);
  }
 }
 sound_close_mixer();
}

canonical_original_code:
void sound_free() {
 int i;
 for( i = 0 ; i < NUM_SOUNDS ; i++ ) {
  if( sounds[i] ) {
   Mix_FreeChunk( sounds[i] );
   sounds[i] = ((void *)0);
  }
 }
 sound_close_mixer();
}


decompiled_code:
__int64 sound_pause()
{
return sound_free();
}

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

original_code:
void sound_pause( void ) {
 sound_free();
}

canonical_original_code:
void sound_pause() {
 sound_free();
}


decompiled_code:
__int64 sound_resume()
{
return sound_init();
}

canonical_decompiled_code:
__int64 func5()
{
return func2();
}

original_code:
int sound_resume( void ) {
 return sound_init();
}

canonical_original_code:
int sound_resume() {
 return sound_init();
}


decompiled_code:
__int64 __fastcall sound_play(unsigned int a1)
{
__int64 v1; // rsi
__int64 result; // rax

if ( mixer_open && a1 <= 3 )
{
v1 = sounds[a1];
if ( v1 )
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, v1, 0LL, 0xFFFFFFFFLL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
__int64 v1; // rsi
__int64 result; // rax

if ( mixer_open && a1 <= 3 )
{
v1 = sounds[a1];
if ( v1 )
result = Mix_PlayChannelTimed(0xFFFFFFFFLL, v1, 0LL, 0xFFFFFFFFLL);
}
return result;
}

original_code:
void sound_play( int s ) {
 if( mixer_open && s >= 0 && s < NUM_SOUNDS && sounds[s] )
  Mix_PlayChannelTimed(-1,sounds[s],0,-1);
}

canonical_original_code:
void sound_play(int s) {
 if( mixer_open && s >= 0 && s < NUM_SOUNDS && sounds[s] )
  Mix_PlayChannelTimed(-1,sounds[s],0,-1);
}

variable_types: s int


decompiled_code:
__int64 __fastcall sound_id(char *s1)
{
__int64 v1; // rbx
unsigned int v2; // er12

if ( !s1 )
return (unsigned int)-1;
v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcasecmp(s1, names[v1]) )
break;
if ( ++v1 == 4 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s1)
{
__int64 v1; // rbx
unsigned int v2; // er12

if ( !s1 )
return (unsigned int)-1;
v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( !strcasecmp(s1, names[v1]) )
break;
if ( ++v1 == 4 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int sound_id( char *name ) {
 int i;
 if( name ) {
  for( i = 0 ; i < NUM_SOUNDS ; i++ ) {
   if( strcasecmp( name, names[i] ) == 0 ) {
    return i;
   }
  }
 }
 return -1;
}

canonical_original_code:
int sound_id(char *name) {
 int i;
 if( name ) {
  for( i = 0 ; i < NUM_SOUNDS ; i++ ) {
   if( strcasecmp( name, names[i] ) == 0 ) {
    return i;
   }
  }
 }
 return -1;
}

variable_types:
name
char *


decompiled_code:
char *__fastcall sound_name(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = names[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func8(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = names[a1];
return result;
}

original_code:
const char *sound_name( int s ) {
 if( s >= 0 && s < NUM_SOUNDS )
  return names[s];
 return ((void *)0);
}

canonical_original_code:
char *sound_name(int s) {
 if( s >= 0 && s < NUM_SOUNDS )
  return names[s];
 return ((void *)0);
}


decompiled_code:
__int64 platform_count()
{
return (unsigned int)count;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)count;
}

original_code:
int platform_count( void ) {
 return count;
}

canonical_original_code:
int platform_count() {
 return count;
}


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

if ( !has_unknown )
{
result = platform_start;
if ( platform_start )
{
platform_unknown = platform_start;
qword_2E8 = *(_QWORD *)(platform_start + 8);
**(_QWORD **)(platform_start + 8) = &platform_unknown;
result = platform_start;
*(_QWORD *)(platform_start + 8) = &platform_unknown;
}
else
{
platform_start = (__int64)&platform_unknown;
platform_unknown = (__int64)&platform_unknown;
qword_2E8 = (__int64)&platform_unknown;
}
++count;
has_unknown = 1;
}
return result;
}

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

if ( !has_unknown )
{
result = platform_start;
if ( platform_start )
{
platform_unknown = platform_start;
qword_2E8 = *(_QWORD *)(platform_start + 8);
**(_QWORD **)(platform_start + 8) = &platform_unknown;
result = platform_start;
*(_QWORD *)(platform_start + 8) = &platform_unknown;
}
else
{
platform_start = (__int64)&platform_unknown;
platform_unknown = (__int64)&platform_unknown;
qword_2E8 = (__int64)&platform_unknown;
}
++count;
has_unknown = 1;
}
return result;
}

original_code:
void platform_add_unknown( void ) {
 if( has_unknown == 0 ) {
  if( platform_start ) {
   platform_unknown.next = platform_start;
   platform_unknown.prev = platform_start->prev;
   platform_start->prev->next = &platform_unknown;
   platform_start->prev = &platform_unknown;
  }
  else {
   platform_start = &platform_unknown;
   platform_start->next = platform_start;
   platform_start->prev = platform_start;
  }
  count++;
  has_unknown = 1;
 }
}

canonical_original_code:
void platform_add_unknown() {
 if( has_unknown == 0 ) {
  if( platform_start ) {
   platform_unknown.next = platform_start;
   platform_unknown.prev = platform_start->prev;
   platform_start->prev->next = &platform_unknown;
   platform_start->prev = &platform_unknown;
  }
  else {
   platform_start = &platform_unknown;
   platform_start->next = platform_start;
   platform_start->prev = platform_start;
  }
  count++;
  has_unknown = 1;
 }
}


decompiled_code:
__int64 platform_free_textures()
{
_QWORD *v0; // rbx
__int64 result; // rax

v0 = (_QWORD *)platform_start;
if ( platform_start )
{
do
{
if ( v0[35] )
{
result = ogl_free_texture();
v0[35] = 0LL;
}
v0 = (_QWORD *)*v0;
}
while ( (_QWORD *)platform_start != v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
_QWORD *v0; // rbx
__int64 result; // rax

v0 = (_QWORD *)platform_start;
if ( platform_start )
{
do
{
if ( v0[35] )
{
result = ogl_free_texture();
v0[35] = 0LL;
}
v0 = (_QWORD *)*v0;
}
while ( (_QWORD *)platform_start != v0 );
}
return result;
}

original_code:
void platform_free_textures( void ) {
 struct platform *p = platform_start;
 if( p ) {
  do {
   if( p->texture ) {
    ogl_free_texture( p->texture );
    p->texture = ((void *)0);
   }
   p = p->next;
  } while( p != platform_start );
 }
}

canonical_original_code:
void platform_free_textures() {
 struct platform *p = platform_start;
 if( p ) {
  do {
   if( p->texture ) {
    ogl_free_texture( p->texture );
    p->texture = ((void *)0);
   }
   p = p->next;
  } while( p != platform_start );
 }
}

variable_types: struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture { unsigned int id; int width; int height; } *texture; } *

user_defined_types: struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture *texture; }


decompiled_code:
__int64 platform_load_textures()
{
__int64 v0; // rbx

v0 = platform_start;
if ( platform_start )
{
do
{
if ( *(_BYTE *)(v0 + 24) )
*(_QWORD *)(v0 + 280) = sdl_create_texture(v0 + 24);
v0 = *(_QWORD *)v0;
}
while ( platform_start != v0 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx

v0 = platform_start;
if ( platform_start )
{
do
{
if ( *(_BYTE *)(v0 + 24) )
*(_QWORD *)(v0 + 280) = sdl_create_texture(v0 + 24);
v0 = *(_QWORD *)v0;
}
while ( platform_start != v0 );
}
return 0LL;
}

original_code:
int platform_load_textures( void ) {
 struct platform *p = platform_start;
 if( p ) {
  do {
   if( p->image_file && p->image_file[0] ) {
    p->texture = sdl_create_texture( p->image_file );
   }
   p = p->next;
  } while( p != platform_start );
 }
 return 0;
}

canonical_original_code:
int platform_load_textures() {
 struct platform *p = platform_start;
 if( p ) {
  do {
   if( p->image_file && p->image_file[0] ) {
    p->texture = sdl_create_texture( p->image_file );
   }
   p = p->next;
  } while( p != platform_start );
 }
 return 0;
}


decompiled_code:
__int64 platform_init()
{
_QWORD *v0; // r14
__int64 v1; // r12
const char *v2; // r13
__int64 v3; // rbx
_QWORD *v4; // rax
__int64 v5; // rbp
__int64 v6; // rax
__int64 result; // rax

v0 = *(_QWORD **)(config_get() + 8);
if ( v0 )
{
while ( 1 )
{
v4 = malloc(0x120uLL);
v5 = (__int64)v4;
if ( !v4 )
break;
memset(v4, 0, 0x120uLL);
v4[2] = v0 + 1;
v6 = image_type_name(3LL);
location_get_match(v6, v0 + 1, v5 + 24);
v3 = platform_start;
if ( platform_start )
{
v1 = *(_QWORD *)(platform_start + 8);
v2 = *(const char **)(v5 + 16);
v3 = v1;
do
{
if ( strcasecmp(*(const char **)(v3 + 16), v2) <= 0 )
break;
v3 = *(_QWORD *)(v3 + 8);
}
while ( v1 != v3 );
}
platform_add((_QWORD *)v5, (__int64 *)v3);
if ( !platform_start || strcasecmp(*(const char **)(v5 + 16), *(const char **)(platform_start + 16)) < 0 )
platform_start = v5;
++count;
v0 = (_QWORD *)*v0;
if ( !v0 )
goto LABEL_15;
}
fwrite("Error: Couldn't allocate memeory for platform object\n", 1uLL, 0x35uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_15:
platform_load_textures();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
_QWORD *v0; // r14
__int64 v1; // r12
const char *v2; // r13
__int64 v3; // rbx
_QWORD *v4; // rax
__int64 v5; // rbp
__int64 v6; // rax
__int64 result; // rax

v0 = *(_QWORD **)(config_get() + 8);
if ( v0 )
{
while ( 1 )
{
v4 = malloc(0x120uLL);
v5 = (__int64)v4;
if ( !v4 )
break;
memset(v4, 0, 0x120uLL);
v4[2] = v0 + 1;
v6 = image_type_name(3LL);
location_get_match(v6, v0 + 1, v5 + 24);
v3 = platform_start;
if ( platform_start )
{
v1 = *(_QWORD *)(platform_start + 8);
v2 = *(const char **)(v5 + 16);
v3 = v1;
do
{
if ( strcasecmp(*(const char **)(v3 + 16), v2) <= 0 )
break;
v3 = *(_QWORD *)(v3 + 8);
}
while ( v1 != v3 );
}
func1((_QWORD *)v5, (__int64 *)v3);
if ( !platform_start || strcasecmp(*(const char **)(v5 + 16), *(const char **)(platform_start + 16)) < 0 )
platform_start = v5;
++count;
v0 = (_QWORD *)*v0;
if ( !v0 )
goto LABEL_15;
}
fwrite("Error: Couldn't allocate memeory for platform object\n", 1uLL, 0x35uLL, stderr);
result = 0xFFFFFFFFLL;
}
else
{
LABEL_15:
func4();
result = 0LL;
}
return result;
}

original_code:
int platform_init( void ) {
 struct config_platform *c = config_get()->platforms;
 struct platform *platform = ((void *)0);
 struct platform *prev = ((void *)0);
 while( c ) {
  platform = malloc( sizeof(struct platform) );
  if( platform ) {
   memset( platform, 0, sizeof(struct platform) );
   platform->name = c->name;
   location_get_match( image_type_name(IMAGE_PLATFORM), platform->name, platform->image_file );
   prev = platform_start;
   if( platform_start ) {
    prev = platform_start->prev;
    while( strcasecmp( prev->name, platform->name ) > 0 ) {
     prev = prev->prev;
     if( prev == platform_start->prev ) break;
    }
   }
   platform_add( platform, prev );
   if( !platform_start || strcasecmp( platform->name, platform_start->name ) < 0 ) {
    platform_start = platform;
   }
   count++;
  }
  else {
   fprintf( stderr, "Error: Couldn't allocate memeory for platform object\n" );
   return -1;
  }
  c = c->next;
 }
 platform_load_textures();
 return 0;
}

canonical_original_code:
int platform_init() {
 struct config_platform *c = config_get()->platforms;
 struct platform *platform = ((void *)0);
 struct platform *prev = ((void *)0);
 while( c ) {
  platform = malloc( sizeof(struct platform) );
  if( platform ) {
   memset( platform, 0, sizeof(struct platform) );
   platform->name = c->name;
   location_get_match( image_type_name(IMAGE_PLATFORM), platform->name, platform->image_file );
   prev = platform_start;
   if( platform_start ) {
    prev = platform_start->prev;
    while( strcasecmp( prev->name, platform->name ) > 0 ) {
     prev = prev->prev;
     if( prev == platform_start->prev ) break;
    }
   }
   platform_add( platform, prev );
   if( !platform_start || strcasecmp( platform->name, platform_start->name ) < 0 ) {
    platform_start = platform;
   }
   count++;
  }
  else {
   fprintf( stderr, "Error: Couldn't allocate memeory for platform object\n" );
   return -1;
  }
  c = c->next;
 }
 platform_load_textures();
 return 0;
}

variable_types: struct config_platform { struct config_platform *next; char name[128]; } *


decompiled_code:
__int64 platform_free()
{
return platform_free_textures();
}

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

original_code:
void platform_free( void ) {
 platform_free_textures();
}

canonical_original_code:
void platform_free() {
 platform_free_textures();
}


decompiled_code:
__int64 platform_pause()
{
return platform_free_textures();
}

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

original_code:
void platform_pause( void ) {
 platform_free_textures();
}

canonical_original_code:
void platform_pause() {
 platform_free_textures();
}


decompiled_code:
__int64 platform_resume()
{
return platform_load_textures();
}

canonical_decompiled_code:
__int64 func8()
{
return func4();
}

original_code:
int platform_resume( void ) {
 return platform_load_textures();
}

canonical_original_code:
int platform_resume() {
 return platform_load_textures();
}


decompiled_code:
__int64 platform_first()
{
return platform_start;
}

canonical_decompiled_code:
__int64 func9()
{
return platform_start;
}

original_code:
struct platform *platform_first( void ) {
 return platform_start;
}

canonical_original_code:
struct platform *platform_first() {
 return platform_start;
}

return_type: struct platform { struct platform *next; struct platform *prev; char *name; char image_file[256]; struct texture { unsigned int id; int width; int height; } *texture; } *


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

result = bg_clear_texture;
bg_texture = bg_clear_texture;
return result;
}

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

result = bg_clear_texture;
bg_texture = bg_clear_texture;
return result;
}

original_code:
void bg_clear( void ) {
 bg_texture = bg_clear_texture;
}

canonical_original_code:
void bg_clear() {
 bg_texture = bg_clear_texture;
}


decompiled_code:
__int64 bg_init()
{
__int64 v0; // rax
_DWORD *v1; // rbx
int v2; // eax
float v3; // xmm0_4
__int64 result; // rax
const char *v5; // rbp
_BYTE v6[280]; // [rsp+0h] [rbp-118h] BYREF

v0 = config_get();
v1 = (_DWORD *)v0;
if ( !*(_BYTE *)(v0 + 952)
|| (v5 = (const char *)(v0 + 952),
location_get_theme_path(v0 + 952, v6),
(bg_clear_texture = sdl_create_texture(v6)) != 0) )
{
*(float *)&alpha = 1.0 - (float)((float)(int)v1[303] / 100.0);
v2 = v1[22];
if ( v2 )
v3 = (float)(int)v1[302] / (float)((float)v2 * 20.0);
else
v3 = (float)(int)v1[302] / 1000.0;
angle_step = LODWORD(v3);
bg_clear();
result = 0LL;
}
else
{
fprintf(stderr, "Warning: couldn't create background texture from '%s'\n", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
_DWORD *v1; // rbx
int v2; // eax
float v3; // xmm0_4
__int64 result; // rax
const char *v5; // rbp
_BYTE v6[280]; // [rsp+0h] [rbp-118h] BYREF

v0 = config_get();
v1 = (_DWORD *)v0;
if ( !*(_BYTE *)(v0 + 952)
|| (v5 = (const char *)(v0 + 952),
location_get_theme_path(v0 + 952, v6),
(bg_clear_texture = sdl_create_texture(v6)) != 0) )
{
*(float *)&alpha = 1.0 - (float)((float)(int)v1[303] / 100.0);
v2 = v1[22];
if ( v2 )
v3 = (float)(int)v1[302] / (float)((float)v2 * 20.0);
else
v3 = (float)(int)v1[302] / 1000.0;
angle_step = LODWORD(v3);
func0();
result = 0LL;
}
else
{
fprintf(stderr, "Warning: couldn't create background texture from '%s'\n", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int bg_init( void ) {
 const struct config *config = config_get();
 char filename[256];
 if( config->iface.theme.background_image[0] != '\0' ) {
  location_get_theme_path( config->iface.theme.background_image , filename );
  bg_clear_texture = sdl_create_texture( filename );
  if( bg_clear_texture == ((void *)0) ) {
   fprintf( stderr, "Warning: couldn't create background texture from '%s'\n", config->iface.theme.background_image );
   return -1;
  }
 }
 alpha = 1.0 - (GLfloat)(config->iface.theme.background_transparency)/100;
 if( config->iface.frame_rate )
  angle_step = (GLfloat)config->iface.theme.background_rotation/((GLfloat)config->iface.frame_rate*20);
 else
  angle_step = (GLfloat)config->iface.theme.background_rotation/1000;
 bg_clear();
 return 0;
}

canonical_original_code:
int bg_init() {
 struct config *config = config_get();
 char filename[256];
 if( config->iface.theme.background_image[0] != '\0' ) {
  location_get_theme_path( config->iface.theme.background_image , filename );
  bg_clear_texture = sdl_create_texture( filename );
  if( bg_clear_texture == ((void *)0) ) {
   fprintf( stderr, "Warning: couldn't create background texture from '%s'\n", config->iface.theme.background_image );
   return -1;
  }
 }
 alpha = 1.0 - (GLfloat)(config->iface.theme.background_transparency)/100;
 if( config->iface.frame_rate )
  angle_step = (float)config->iface.theme.background_rotation/((float)config->iface.frame_rate*20);
 else
  angle_step = (float)config->iface.theme.background_rotation/1000;
 bg_clear();
 return 0;
}

variable_types:
filename
char [256]

user_defined_types: struct config { struct config_emulator *emulators; struct config_platform *platforms; struct config_category *categories; struct config_game *games; struct config_theme *themes; struct config_image_type *image_types; struct config_location *locations; struct config_location_type *location_types; struct config_iface iface; }

user_defined_types: struct config_iface { int full_screen; int screen_width; int screen_height; int screen_rotation; int screen_hflip; int screen_vflip; int frame_rate; int gfx_quality; int gfx_max_width; int gfx_max_height; int prune_menus; struct config_labels labels; struct config_control controls[-1]; char theme_name[128]; struct config_theme theme; }

user_defined_types: struct config_emulator { struct config_emulator *next; int id; char name[128]; char display_name[128]; char executable[256]; char directory[256]; int is_default; struct config_param *params; struct config_platform *platform; }

user_defined_types: struct config_category { struct config_category *next; int id; char name[128]; struct config_category_value *values; struct config_lookup *lookups; }

user_defined_types: struct config_game { struct config_game *next; char name[128]; char rom_image[256]; char video[256]; char emulator[128]; struct config_game_category *categories; struct config_param *params; struct config_platform *platform; struct config_image *images; }

user_defined_types: struct config_theme { struct config_theme *next; char name[128]; char directory[256]; char background_image[256]; int background_rotation; int background_transparency; char sounds[-1][256]; char font_file[256]; int font_size; struct config_rgb font_rgb; struct config_menu menu; struct config_submenu submenu; struct config_game_sel game_sel; struct config_snap snap; struct config_hints hints; }

user_defined_types: struct config_location { struct config_location *next; struct config_location_type *type; char directory[256]; }

user_defined_types: struct config_labels { char label_all[32]; char label_platform[32]; char label_back[32]; char label_select[32]; char label_lists[32]; }

user_defined_types: struct config_game_sel { float offset1; float offset2; float size_x; float size_y; float tile_size; int orientation; int selected; struct config_game_sel_tile *tiles; }

user_defined_types: struct config_image { struct config_image *next; struct config_image_type *type; char file_name[256]; }


decompiled_code:
__int64 bg_free()
{
if ( bg_texture != bg_clear_texture )
((void (*)(void))ogl_free_texture)();
return ogl_free_texture(bg_texture);
}

canonical_decompiled_code:
__int64 func2()
{
if ( bg_texture != bg_clear_texture )
((void (*)(void))ogl_free_texture)();
return ogl_free_texture(bg_texture);
}

original_code:
void bg_free( void ) {
 if( bg_texture != bg_clear_texture ) {
  ogl_free_texture( bg_clear_texture );
 }
 ogl_free_texture( bg_texture );
}

canonical_original_code:
void bg_free() {
 if( bg_texture != bg_clear_texture ) {
  ogl_free_texture( bg_clear_texture );
 }
 ogl_free_texture( bg_texture );
}


decompiled_code:
__int64 bg_pause()
{
return bg_free();
}

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

original_code:
void bg_pause( void ) {
 bg_free();
}

canonical_original_code:
void bg_pause() {
 bg_free();
}


decompiled_code:
__int64 bg_resume()
{
return bg_init();
}

canonical_decompiled_code:
__int64 func4()
{
return func1();
}

original_code:
int bg_resume( void ) {
 return bg_init();
}

canonical_original_code:
int bg_resume() {
 return bg_init();
}


decompiled_code:
__int64 __fastcall bg_set(const char *a1)
{
__int64 result; // rax

if ( a1 && *a1 )
{
if ( bg_texture != bg_clear_texture )
ogl_free_texture(bg_texture);
bg_texture = sdl_create_texture(a1);
if ( bg_texture )
{
result = 0LL;
}
else
{
fprintf(stderr, "Warning: couldn't load background image '%s'\n", a1);
result = 0xFFFFFFFFLL;
}
}
else
{
bg_clear();
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
__int64 result; // rax

if ( a1 && *a1 )
{
if ( bg_texture != bg_clear_texture )
ogl_free_texture(bg_texture);
bg_texture = sdl_create_texture(a1);
if ( bg_texture )
{
result = 0LL;
}
else
{
fprintf(stderr, "Warning: couldn't load background image '%s'\n", a1);
result = 0xFFFFFFFFLL;
}
}
else
{
func0();
result = 0LL;
}
return result;
}

original_code:
int bg_set( const char *filename ) {
 if( filename && *filename ) {
  if( bg_texture != bg_clear_texture ) {
   ogl_free_texture( bg_texture );
  }
  bg_texture = sdl_create_texture( filename );
  if( bg_texture == 0 ) {
   fprintf( stderr, "Warning: couldn't load background image '%s'\n", filename );
   return -1;
  }
 }
 else {
  bg_clear();
 }
 return 0;
}

canonical_original_code:
int bg_set(char *filename) {
 if( filename && *filename ) {
  if( bg_texture != bg_clear_texture ) {
   ogl_free_texture( bg_texture );
  }
  bg_texture = sdl_create_texture( filename );
  if( bg_texture == 0 ) {
   fprintf( stderr, "Warning: couldn't load background image '%s'\n", filename );
   return -1;
  }
 }
 else {
  bg_clear();
 }
 return 0;
}

variable_types:
filename
char *


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

if ( bg_texture )
{
ogl_load_alterego();
glEnable(3553LL);
glTexEnvf(8960LL, 8704LL, 8448.0);
glBindTexture(3553LL, *(unsigned int *)bg_texture);
glColor4f(1.0, 1.0, 1.0, *(float *)&alpha);
glBlendFunc(770LL, 771LL);
glRotatef(*(float *)&angle, 0.0, 0.0, 1.0);
glTranslatef(0.0, 0.0, -10.0);
glBegin(7LL);
glTexCoord2f(0.0);
glVertex3f(-7.0, 7.0, 0.0);
glTexCoord2f(0.0);
glVertex3f(-7.0, -7.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(7.0, -7.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(7.0, 7.0, 0.0);
glEnd();
result = glDisable(3553LL);
*(float *)&angle = *(float *)&angle - *(float *)&angle_step;
}
return result;
}

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

if ( bg_texture )
{
ogl_load_alterego();
glEnable(3553LL);
glTexEnvf(8960LL, 8704LL, 8448.0);
glBindTexture(3553LL, *(unsigned int *)bg_texture);
glColor4f(1.0, 1.0, 1.0, *(float *)&alpha);
glBlendFunc(770LL, 771LL);
glRotatef(*(float *)&angle, 0.0, 0.0, 1.0);
glTranslatef(0.0, 0.0, -10.0);
glBegin(7LL);
glTexCoord2f(0.0);
glVertex3f(-7.0, 7.0, 0.0);
glTexCoord2f(0.0);
glVertex3f(-7.0, -7.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(7.0, -7.0, 0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC2));
glVertex3f(7.0, 7.0, 0.0);
glEnd();
result = glDisable(3553LL);
*(float *)&angle = *(float *)&angle - *(float *)&angle_step;
}
return result;
}

original_code:
void bg_draw( void ) {
 if( bg_texture ) {
  ogl_load_alterego();
  glEnable( 0x0DE1 );
  glTexEnvf( 0x2300, 0x2200, 0x2100 );
  glBindTexture( 0x0DE1, bg_texture->id );
  glColor4f( 1.0, 1.0, 1.0, alpha );
  glBlendFunc(0x0302,0x0303);
  glRotatef( angle, 0.0, 0.0, 1.0 );
  glTranslatef( 0.0, 0.0, -10.0 );
  glBegin( 0x0007 );
   glTexCoord2f(0.0, 0.0); glVertex3f( -BG_SIZE, BG_SIZE, 0.0 );
   glTexCoord2f(0.0, 1.0); glVertex3f( -BG_SIZE, -BG_SIZE, 0.0 );
   glTexCoord2f(1.0, 1.0); glVertex3f( BG_SIZE, -BG_SIZE, 0.0 );
   glTexCoord2f(1.0, 0.0); glVertex3f( BG_SIZE, BG_SIZE, 0.0 );
  glEnd();
  glDisable( 0x0DE1 );
  angle -= angle_step;
 }
}

canonical_original_code:
void bg_draw() {
 if( bg_texture ) {
  ogl_load_alterego();
  glEnable( 0x0DE1 );
  glTexEnvf( 0x2300, 0x2200, 0x2100 );
  glBindTexture( 0x0DE1, bg_texture->id );
  glColor4f( 1.0, 1.0, 1.0, alpha );
  glBlendFunc(0x0302,0x0303);
  glRotatef( angle, 0.0, 0.0, 1.0 );
  glTranslatef( 0.0, 0.0, -10.0 );
  glBegin( 0x0007 );
   glTexCoord2f(0.0, 0.0); glVertex3f( -BG_SIZE, BG_SIZE, 0.0 );
   glTexCoord2f(0.0, 1.0); glVertex3f( -BG_SIZE, -BG_SIZE, 0.0 );
   glTexCoord2f(1.0, 1.0); glVertex3f( BG_SIZE, -BG_SIZE, 0.0 );
   glTexCoord2f(1.0, 0.0); glVertex3f( BG_SIZE, BG_SIZE, 0.0 );
  glEnd();
  glDisable( 0x0DE1 );
  angle -= angle_step;
 }
}


decompiled_code:
__int64 event_init()
{
__int64 v0; // rbx
int v1; // eax
int v2; // ebp
__int64 i; // rax

v0 = config_get();
v1 = SDL_NumJoysticks();
num_joysticks = v1;
if ( v1 <= 8 )
{
if ( v1 <= 0 )
goto LABEL_5;
}
else
{
num_joysticks = 8;
}
v2 = 0;
do
SDL_JoystickOpen((unsigned int)v2++);
while ( num_joysticks > v2 );
LABEL_5:
for ( i = 0LL; i != 35; i += 5LL )
{
dword_814[i] = *(_DWORD *)(v0 + i * 4 + 288);
dword_818[i] = *(_DWORD *)(v0 + i * 4 + 292);
dword_81C[i] = *(_DWORD *)(v0 + i * 4 + 296);
dword_820[i] = *(_DWORD *)(v0 + i * 4 + 300);
dword_824[i] = *(_DWORD *)(v0 + i * 4 + 304);
}
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbx
int v1; // eax
int v2; // ebp
__int64 i; // rax

v0 = config_get();
v1 = SDL_NumJoysticks();
num_joysticks = v1;
if ( v1 <= 8 )
{
if ( v1 <= 0 )
goto LABEL_5;
}
else
{
num_joysticks = 8;
}
v2 = 0;
do
SDL_JoystickOpen((unsigned int)v2++);
while ( num_joysticks > v2 );
LABEL_5:
for ( i = 0LL; i != 35; i += 5LL )
{
dword_814[i] = *(_DWORD *)(v0 + i * 4 + 288);
dword_818[i] = *(_DWORD *)(v0 + i * 4 + 292);
dword_81C[i] = *(_DWORD *)(v0 + i * 4 + 296);
dword_820[i] = *(_DWORD *)(v0 + i * 4 + 300);
dword_824[i] = *(_DWORD *)(v0 + i * 4 + 304);
}
return 0LL;
}

original_code:
int event_init( void ) {
 const struct config* config = config_get();
 int i;
 num_joysticks = SDL_NumJoysticks();
 if( num_joysticks > 8 )
  num_joysticks = 8;
 for( i = 0 ; i < num_joysticks ; i++ ) {
  SDL_JoystickOpen( i );
 }
 for( i = 1 ; i < NUM_EVENTS ; i++ ) {
  events[i].device_type = config->iface.controls[i].device_type;
  events[i].device_id = config->iface.controls[i].device_id;
  events[i].control_type = config->iface.controls[i].control_type;
  events[i].control_id = config->iface.controls[i].control_id;
  events[i].value = config->iface.controls[i].value;
 }
 return 0;
}

canonical_original_code:
int event_init() {
 struct config *config = config_get();
 int i;
 num_joysticks = SDL_NumJoysticks();
 if( num_joysticks > 8 )
  num_joysticks = 8;
 for( i = 0 ; i < num_joysticks ; i++ ) {
  SDL_JoystickOpen( i );
 }
 for( i = 1 ; i < NUM_EVENTS ; i++ ) {
  events[i].device_type = config->iface.controls[i].device_type;
  events[i].device_id = config->iface.controls[i].device_id;
  events[i].control_type = config->iface.controls[i].control_type;
  events[i].control_id = config->iface.controls[i].control_id;
  events[i].value = config->iface.controls[i].value;
 }
 return 0;
}

variable_types: i int

user_defined_types: struct config_rgb { unsigned char red; unsigned char green; unsigned char blue; }

user_defined_types: struct config_menu { char texture[256]; float item_width; float item_height; float font_scale; float zoom; int transparency; float offset1; float offset2; int max_visible; float spacing; int orientation; int auto_hide; int border; }

user_defined_types: struct config_submenu { char texture[256]; float item_width; float item_height; float font_scale; float offset1; float offset2; }

user_defined_types: struct config_snap { float offset1; float offset2; float angle_x; float angle_y; float angle_z; float size; int fix_aspect_ratio; int auto_hide; int platform_icons; }

user_defined_types: struct config_hints { float offset1; float offset2; float size; float spacing; int pulse; char image_back[256]; char image_select[256]; char image_arrow[256]; }

user_defined_types: struct config_control { int device_type; int device_id; int control_type; int control_id; int value; }

user_defined_types: struct config_param { struct config_param *next; char name[64]; char value[64]; }

user_defined_types: struct config_platform { struct config_platform *next; char name[128]; }

user_defined_types: struct config_category_value { struct config_category_value *next; char name[128]; }

user_defined_types: struct config_lookup { struct config_lookup *next; char match[32]; char value[32]; }


decompiled_code:
__int64 event_free()
{
int v0; // ebx
__int64 result; // rax

if ( num_joysticks > 0 )
{
v0 = 0;
do
{
result = SDL_JoystickClose(0LL);
++v0;
}
while ( num_joysticks > v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // ebx
__int64 result; // rax

if ( num_joysticks > 0 )
{
v0 = 0;
do
{
result = SDL_JoystickClose(0LL);
++v0;
}
while ( num_joysticks > v0 );
}
return result;
}

original_code:
void event_free( void ) {
 int i;
 for( i = 0 ; i < num_joysticks ; i++ ) {
  SDL_JoystickClose( joysticks[i] );
 }
}

canonical_original_code:
void event_free() {
 int i;
 for( i = 0 ; i < num_joysticks ; i++ ) {
  SDL_JoystickClose( joysticks[i] );
 }
}


decompiled_code:
__int64 event_pause()
{
return event_free();
}

canonical_decompiled_code:
__int64 func2()
{
return func1();
}

original_code:
void event_pause( void ) {
 event_free();
}

canonical_original_code:
void event_pause() {
 event_free();
}


decompiled_code:
__int64 event_resume()
{
return event_init();
}

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

original_code:
int event_resume( void ) {
 return event_init();
}

canonical_original_code:
int event_resume() {
 return event_init();
}


decompiled_code:
__int64 __fastcall event_set(unsigned int a1, const __m128i *a2)
{
__int64 v2; // rax
__int64 result; // rax

if ( a1 - 1 > 6 )
{
fprintf(stderr, "Warning: Can't set non-existent event %d\n", a1);
result = 0xFFFFFFFFLL;
}
else
{
v2 = 5LL * (int)a1;
*(__int128 *)((char *)&events + v2 * 4) = (__int128)_mm_loadu_si128(a2);
dword_810[v2] = a2[1].m128i_i32[0];
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, const __m128i *a2)
{
__int64 v2; // rax
__int64 result; // rax

if ( a1 - 1 > 6 )
{
fprintf(stderr, "Warning: Can't set non-existent event %d\n", a1);
result = 0xFFFFFFFFLL;
}
else
{
v2 = 5LL * (int)a1;
*(__int128 *)((char *)&events + v2 * 4) = (__int128)_mm_loadu_si128(a2);
dword_810[v2] = a2[1].m128i_i32[0];
result = 0LL;
}
return result;
}

original_code:
int event_set( int id, struct event *event ) {
 if( id < 1 || id >= NUM_EVENTS ) {
  fprintf( stderr, "Warning: Can't set non-existent event %d\n", id );
  return -1;
 }
 memcpy( &events[id], event, sizeof(struct event) );
 return 0;
}

canonical_original_code:
int event_set(int id, struct event *event) {
 if( id < 1 || id >= NUM_EVENTS ) {
  fprintf( stderr, "Warning: Can't set non-existent event %d\n", id );
  return -1;
 }
 memcpy( &events[id], event, sizeof(struct event) );
 return 0;
}

variable_types: id int

variable_types: struct event { int device_type; int device_id; int control_type; int control_id; int value; } *


decompiled_code:
char *__fastcall event_get(unsigned int a1)
{
if ( a1 - 1 <= 6 )
return (char *)&events + 20 * (int)a1;
fprintf(stderr, "Warning: Can't get non-existent event %d\n", a1);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned int a1)
{
if ( a1 - 1 <= 6 )
return (char *)&events + 20 * (int)a1;
fprintf(stderr, "Warning: Can't get non-existent event %d\n", a1);
return 0LL;
}

original_code:
struct event *event_get( int id ) {
 if( id < 1 || id >= NUM_EVENTS ) {
  fprintf( stderr, "Warning: Can't get non-existent event %d\n", id );
  return ((void *)0);
 }
 return &events[id];
}

canonical_original_code:
struct event *event_get(int id) {
 if( id < 1 || id >= NUM_EVENTS ) {
  fprintf( stderr, "Warning: Can't get non-existent event %d\n", id );
  return ((void *)0);
 }
 return &events[id];
}

return_type: struct event { int device_type; int device_id; int control_type; int control_id; int value; } *


decompiled_code:
__int64 __fastcall event_process(unsigned int a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax

v1 = focus_has();
if ( v1 == 1 )
{
submenu_event(a1);
v2 = 0;
}
else
{
v2 = v1;
if ( v1 == 2 )
{
game_sel_event(a1);
v2 = 0;
}
else if ( v1 )
{
v3 = focus_has();
fprintf(stderr, "Error: Unknown focus %d\n", v3);
v2 = -1;
}
else
{
menu_event(a1);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
unsigned int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax

v1 = focus_has();
if ( v1 == 1 )
{
submenu_event(a1);
v2 = 0;
}
else
{
v2 = v1;
if ( v1 == 2 )
{
game_sel_event(a1);
v2 = 0;
}
else if ( v1 )
{
v3 = focus_has();
fprintf(stderr, "Error: Unknown focus %d\n", v3);
v2 = -1;
}
else
{
menu_event(a1);
}
}
return v2;
}

original_code:
int event_process( int e ) {
 switch( focus_has() ) {
  case FOCUS_MENU:
   menu_event( e );
   break;
  case FOCUS_SUBMENU:
   submenu_event( e );
   break;
  case FOCUS_GAMESEL:
   game_sel_event( e );
   break;
  default:
   fprintf( stderr, "Error: Unknown focus %d\n", focus_has() );
   return -1;
   break;
 }
 return 0;
}

canonical_original_code:
int event_process(int e) {
 switch( focus_has() ) {
  case FOCUS_MENU:
   menu_event( e );
   break;
  case FOCUS_SUBMENU:
   submenu_event( e );
   break;
  case FOCUS_GAMESEL:
   game_sel_event( e );
   break;
  default:
   fprintf( stderr, "Error: Unknown focus %d\n", focus_has() );
   return -1;
   break;
 }
 return 0;
}

variable_types: e int


decompiled_code:
__int64 __fastcall event_id(char *s1)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
if ( s1 )
{
while ( 1 )
{
v2 = v1;
if ( !strcasecmp(s1, event_str[v1]) )
break;
if ( ++v1 == 8 )
{
fprintf(stderr, "Warning: Unknown event name '%s'\n", s1);
return 0;
}
}
}
else
{
fwrite("Warning: Null event name\n", 1uLL, 0x19uLL, stderr);
v2 = 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s1)
{
__int64 v1; // rbx
unsigned int v2; // er12

v1 = 0LL;
if ( s1 )
{
while ( 1 )
{
v2 = v1;
if ( !strcasecmp(s1, event_str[v1]) )
break;
if ( ++v1 == 8 )
{
fprintf(stderr, "Warning: Unknown event name '%s'\n", s1);
return 0;
}
}
}
else
{
fwrite("Warning: Null event name\n", 1uLL, 0x19uLL, stderr);
v2 = 0;
}
return v2;
}

original_code:
int event_id( char *name ) {
 int i;
 if( name == ((void *)0) ) {
  fprintf( stderr, "Warning: Null event name\n" );
  return EVENT_NONE;
 }
 for( i = 0 ; i < NUM_EVENTS ; i++ ) {
  if( strcasecmp( name, event_str[i] ) == 0 ) return i;
 }
 fprintf( stderr, "Warning: Unknown event name '%s'\n", name );
 return EVENT_NONE;
}

canonical_original_code:
int event_id(char *name) {
 int i;
 if( name == ((void *)0) ) {
  fprintf( stderr, "Warning: Null event name\n" );
  return EVENT_NONE;
 }
 for( i = 0 ; i < NUM_EVENTS ; i++ ) {
  if( strcasecmp( name, event_str[i] ) == 0 ) return i;
 }
 fprintf( stderr, "Warning: Unknown event name '%s'\n", name );
 return EVENT_NONE;
}


decompiled_code:
char *__fastcall event_name(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 8 )
result = event_str[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func11(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 8 )
result = event_str[a1];
return result;
}

original_code:
const char *event_name( int event ) {
 if( event < 0 || event > NUM_EVENTS )
  return ((void *)0);
 else
  return event_str[event];
}

canonical_original_code:
char *event_name(int event) {
 if( event < 0 || event > NUM_EVENTS )
  return ((void *)0);
 else
  return event_str[event];
}

variable_types: event int


decompiled_code:
char *__fastcall media_type_name(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = media_types[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = media_types[a1];
return result;
}

original_code:
char *media_type_name( int m ) {
 if( m >= 0 && m < NUM_IMAGE_TYPES )
  return (char*)media_types[m];
 return ((void *)0);
}

canonical_original_code:
char *media_type_name(int m) {
 if( m >= 0 && m < NUM_IMAGE_TYPES )
  return (char *)media_types[m];
 return ((void *)0);
}

variable_types: m int


decompiled_code:
char *__fastcall image_type_name(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = image_types[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func1(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 3 )
result = image_types[a1];
return result;
}

original_code:
char *image_type_name( int i ) {
 if( i >= 0 && i < NUM_IMAGE_TYPES )
  return (char*)image_types[i];
 return ((void *)0);
}

canonical_original_code:
char *image_type_name(int i) {
 if( i >= 0 && i < NUM_IMAGE_TYPES )
  return (char *)image_types[i];
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall next_power_of_two(unsigned int a1)
{
__int64 result; // rax
char v2; // cl

result = 1LL;
if ( a1 )
{
v2 = 0;
do
{
++v2;
a1 >>= 1;
}
while ( a1 );
result = (unsigned int)(1 << v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 result; // rax
char v2; // cl

result = 1LL;
if ( a1 )
{
v2 = 0;
do
{
++v2;
a1 >>= 1;
}
while ( a1 );
result = (unsigned int)(1 << v2);
}
return result;
}

original_code:
unsigned int next_power_of_two( unsigned int x ) {
        int i = 0;
        if( x == 0 ) return 1;
        for( i = 0; x > 0 ; i++, x>>=1 );
        return 1<<i;
}

canonical_original_code:
unsigned int next_power_of_two(unsigned int x) {
        int i = 0;
        if( x == 0 ) return 1;
        for( i = 0; x > 0 ; i++, x>>=1 );
        return 1<<i;
}

variable_types:
x
unsigned int

return_type: unsigned int


repo: tuxoko/acm

original_code:
void reset_blocks_on(int a)
{
 int p, t;
 for (t = p = blocks[a].next; p != -1; p = t) {
  t = blocks[p].next;
  blocks[p].pos = p;
  blocks[p].next = -1;
  blocks[p].prev = pos[p].end;
  if (pos[p].end >= 0)
   blocks[pos[p].end].next = p;
  else
   pos[p].first = p;
  pos[p].end = p;
 }
 blocks[a].next = -1;
 pos[blocks[a].pos].end = a;
}

canonical_original_code:
void reset_blocks_on(int a)
{
 int p; int t;
 for (t = p = blocks[a].next; p != -1; p = t) {
  t = blocks[p].next;
  blocks[p].pos = p;
  blocks[p].next = -1;
  blocks[p].prev = pos[p].end;
  if (pos[p].end >= 0)
   blocks[pos[p].end].next = p;
  else
   pos[p].first = p;
  pos[p].end = p;
 }
 blocks[a].next = -1;
 pos[blocks[a].pos].end = a;
}

variable_types: a int

variable_types: p int

variable_types: t int


decompiled_code:
__int64 __fastcall pile_over(unsigned int a1, int a2)
{
__int64 result; // rax
int v3; // edx
int v4; // ecx
int v5; // er8
int v6; // esi

result = a1;
v3 = dword_404064[2 * blocks[3 * a2]];
v4 = blocks[3 * a1];
v5 = dword_404064[2 * v4];
v6 = dword_404148[3 * a1];
if ( v6 < 0 )
pos[2 * v4] = -1;
else
dword_404144[3 * v6] = -1;
dword_404064[2 * v4] = v6;
dword_404064[2 * blocks[3 * v3]] = v5;
dword_404144[3 * v3] = a1;
dword_404148[3 * a1] = v3;
if ( a1 != -1 )
{
do
{
blocks[3 * (int)result] = blocks[3 * v3];
result = (unsigned int)dword_404144[3 * (int)result];
}
while ( (_DWORD)result != -1 );
}
return result;
}

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

result = a1;
v3 = dword_404064[2 * blocks[3 * a2]];
v4 = blocks[3 * a1];
v5 = dword_404064[2 * v4];
v6 = dword_404148[3 * a1];
if ( v6 < 0 )
pos[2 * v4] = -1;
else
dword_404144[3 * v6] = -1;
dword_404064[2 * v4] = v6;
dword_404064[2 * blocks[3 * v3]] = v5;
dword_404144[3 * v3] = a1;
dword_404148[3 * a1] = v3;
if ( a1 != -1 )
{
do
{
blocks[3 * (int)result] = blocks[3 * v3];
result = (unsigned int)dword_404144[3 * (int)result];
}
while ( (_DWORD)result != -1 );
}
return result;
}

original_code:
void pile_over(int a, int b)
{
 int p, end;
 b = pos[blocks[b].pos].end;
 end = pos[blocks[a].pos].end;
 if (blocks[a].prev >= 0)
  blocks[blocks[a].prev].next = -1;
 else
  pos[blocks[a].pos].first = -1;
 pos[blocks[a].pos].end = blocks[a].prev;
 pos[blocks[b].pos].end = end;
 blocks[b].next = a;
 blocks[a].prev = b;
 for (p = a; p != -1; p = blocks[p].next)
  blocks[p].pos = blocks[b].pos;
}

canonical_original_code:
void pile_over(int a, int b)
{
 int p; int end;
 b = pos[blocks[b].pos].end;
 end = pos[blocks[a].pos].end;
 if (blocks[a].prev >= 0)
  blocks[blocks[a].prev].next = -1;
 else
  pos[blocks[a].pos].first = -1;
 pos[blocks[a].pos].end = blocks[a].prev;
 pos[blocks[b].pos].end = end;
 blocks[b].next = a;
 blocks[a].prev = b;
 for (p = a; p != -1; p = blocks[p].next)
  blocks[p].pos = blocks[b].pos;
}

variable_types: b int

variable_types: end int


main

canonical_name: main

original_code:
int main(int argc, char *argv[])
{
 int i, j, a, b, n;
 char cmd1[8], cmd2[8];
 j = scanf("%d", &n);
 for (i = 0; i < n; i++) {
  blocks[i].pos = i;
  blocks[i].next = -1;
  blocks[i].prev = -1;
  pos[i].first = i;
  pos[i].end = i;
 }
 while (scanf("%s", cmd1) == 1) {
  if (cmd1[0] == 'q')
   break;
  j = scanf("%d%s%d", &a, cmd2, &b);
  if (a == b || blocks[a].pos == blocks[b].pos)
   continue;
  if (cmd1[0] == 'm')
   reset_blocks_on(a);
  if (cmd2[1] == 'n')
   reset_blocks_on(b);
  pile_over(a, b);
 }
 for (i = 0; i < n; i++) {
  printf("%d:", i);
  for (j = pos[i].first; j != -1; j = blocks[j].next)
   printf(" %d", j);
  printf("\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i; int j; int a; int b; int n;
 char cmd1[8]; char cmd2[8];
 j = scanf("%d", &n);
 for (i = 0; i < n; i++) {
  blocks[i].pos = i;
  blocks[i].next = -1;
  blocks[i].prev = -1;
  pos[i].first = i;
  pos[i].end = i;
 }
 while (scanf("%s", cmd1) == 1) {
  if (cmd1[0] == 'q')
   break;
  j = scanf("%d%s%d", &a, cmd2, &b);
  if (a == b || blocks[a].pos == blocks[b].pos)
   continue;
  if (cmd1[0] == 'm')
   reset_blocks_on(a);
  if (cmd2[1] == 'n')
   reset_blocks_on(b);
  pile_over(a, b);
 }
 for (i = 0; i < n; i++) {
  printf("%d:", i);
  for (j = pos[i].first; j != -1; j = blocks[j].next)
   printf(" %d", j);
  printf("\n");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: j int

variable_types: n int


fetch

repo: tuxology/vyantra

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

v0 = pc++;
return (unsigned int)insn_buff[v0];
}

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

v0 = pc++;
return (unsigned int)insn_buff[v0];
}

original_code:
int fetch(){
    return insn_buff[pc++];
}

canonical_original_code:
int fetch(){
    return insn_buff[pc++];
}


decode

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

instr_num = HIBYTE(a1);
r1 = (a1 >> 20) & 0xF;
r2 = (a1 >> 16) & 0xF;
result = (a1 >> 12) & 0xF;
r3 = (a1 >> 12) & 0xF;
val = (unsigned __int8)a1;
return result;
}

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

instr_num = HIBYTE(a1);
r1 = (a1 >> 20) & 0xF;
r2 = (a1 >> 16) & 0xF;
result = (a1 >> 12) & 0xF;
r3 = (a1 >> 12) & 0xF;
val = (unsigned __int8)a1;
return result;
}

variable_types: instr int


eval

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

result = (unsigned int)instr_num;
switch ( instr_num )
{
case 0:
running = 0;
break;
case 1:
result = r2;
regs[r2] = regs[r3];
break;
case 2:
result = r1;
regs[r1] = val;
break;
case 3:
result = (unsigned int)(regs[r2] + regs[r3]);
regs[r1] = result;
break;
case 4:
result = (unsigned int)(regs[r2] - regs[r3]);
regs[r1] = result;
break;
case 5:
result = (unsigned int)(regs[r3] * regs[r2]);
regs[r1] = result;
break;
case 6:
result = regs[r2] / (unsigned int)regs[r3];
regs[r1] = result;
break;
default:
return result;
}
return result;
}

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

result = (unsigned int)instr_num;
switch ( instr_num )
{
case 0:
running = 0;
break;
case 1:
result = r2;
regs[r2] = regs[r3];
break;
case 2:
result = r1;
regs[r1] = val;
break;
case 3:
result = (unsigned int)(regs[r2] + regs[r3]);
regs[r1] = result;
break;
case 4:
result = (unsigned int)(regs[r2] - regs[r3]);
regs[r1] = result;
break;
case 5:
result = (unsigned int)(regs[r3] * regs[r2]);
regs[r1] = result;
break;
case 6:
result = regs[r2] / (unsigned int)regs[r3];
regs[r1] = result;
break;
default:
return result;
}
return result;
}

original_code:
void eval(){
    switch(instr_num)
    {
        case 0:
            running = 0;
            break;
        case 1:
            regs[r2] = regs[r3];
            break;
        case 2:
            regs[r1] = val;
            break;
        case 3:
            regs[r1] = regs[r2] + regs[r3];
            break;
        case 4:
            regs[r1] = regs[r2] - regs[r3];
            break;
        case 5:
            regs[r1] = regs[r2] * regs[r3];
            break;
        case 6:
            regs[r1] = regs[r2] / regs[r3];
            break;
    }
}


showRegs

decompiled_code:
int showRegs()
{
unsigned int *v0; // rbx

printf("regs = ");
v0 = (unsigned int *)regs;
do
printf("%08X ", *v0++);
while ( v0 != (unsigned int *)&end );
return putchar(10);
}

canonical_decompiled_code:
int func10()
{
unsigned int *v0; // rbx

printf("regs = ");
v0 = (unsigned int *)regs;
do
printf("%08X ", *v0++);
while ( v0 != (unsigned int *)&end );
return putchar(10);
}

original_code:
void showRegs(){
    int i;
    printf("regs = ");
    for( i=0; i<4; i++ )
        printf( "%08X ", regs[i]);
    printf( "\n" );
}

variable_types: i int


run

decompiled_code:
void run()
{
int v0; // eax

while ( running )
{
showRegs();
v0 = fetch();
decode(v0);
eval();
}
}

canonical_decompiled_code:
void func11()
{
int v0; // eax

while ( running )
{
func10();
v0 = func7();
func8(v0);
func9();
}
}

original_code:
void run(){
    while(running){
        showRegs();
        int instr = fetch();
        decode(instr);
        eval();
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
prep_binary("./test.yex");
run();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
prep_binary("./test.yex");
func11();
return 0;
}

original_code:
int main(int argc, const char * argv[]){
    prep_binary("./test.yex");
    int j = 0;
    run();
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
    prep_binary("./test.yex");
    int j = 0;
    run();
    return 0;
}


decompiled_code:
__int64 __fastcall parse_line(char *s)
{
char *v1; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

if ( strchr("!", *s) )
{
v1 = strtok(s, "!");
printf("COMMAND : %s", v1);
}
if ( *s == 9 || *s == 32 )
{
v3 = strtok(s, " ");
printf("INSTR : %s\n", v3);
v4 = strtok(0LL, " ");
printf("ARG1 : %s\n", v4);
v5 = strtok(0LL, " ");
printf("ARG2 : %s\n", v5);
v6 = strtok(0LL, " ");
printf("ARG3 : %s\n", v6);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s)
{
char *v1; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

if ( strchr("!", *s) )
{
v1 = strtok(s, "!");
printf("COMMAND : %s", v1);
}
if ( *s == 9 || *s == 32 )
{
v3 = strtok(s, " ");
printf("INSTR : %s\n", v3);
v4 = strtok(0LL, " ");
printf("ARG1 : %s\n", v4);
v5 = strtok(0LL, " ");
printf("ARG2 : %s\n", v5);
v6 = strtok(0LL, " ");
printf("ARG3 : %s\n", v6);
}
return 0LL;
}

original_code:
int parse_line(char *line, unsigned buff[]) {
    char *instr = ((void *)0);
    char *cmd = ((void *)0);
    char *reg = ((void *)0);
    char *arg1, *arg2, *arg3 = ((void *)0);
    char *ls_reg = ((void *)0);
    char *op_regs = ((void *)0);
    char *val = ((void *)0);
    if (strchr("!", *line)) {
        cmd = strtok(line, "!");
        printf("COMMAND : %s", cmd);
    }
    if (line[0] == '\t' || line[0] == ' ') {
        int i = 0;
        while (i < sizeof(line)/sizeof(char*)) {
            instr = strtok(line, " ");
            printf("INSTR : %s\n", instr);
            arg1 = strtok(((void *)0), " ");
            printf("ARG1 : %s\n", arg1);
            arg2 = strtok(((void *)0), " ");
            printf("ARG2 : %s\n", arg2);
            arg3 = strtok(((void *)0), " ");
            printf("ARG3 : %s\n", arg3);
            i++;
        }
    }
    return 0;
}

canonical_original_code:
int parse_line(char *line, unsigned int buff[]) {
    char *instr = ((void *)0);
    char *cmd = ((void *)0);
    char *reg = ((void *)0);
    char *arg1; char *arg2; char *arg3 = ((void *)0);
    char *ls_reg = ((void *)0);
    char *op_regs = ((void *)0);
    char *val = ((void *)0);
    if (strchr("!", *line)) {
        cmd = strtok(line, "!");
        printf("COMMAND : %s", cmd);
    }
    if (line[0] == '\t' || line[0] == ' ') {
        int i = 0;
        while (i < sizeof(line)/sizeof(char *)) {
            instr = strtok(line, " ");
            printf("INSTR : %s\n", instr);
            arg1 = strtok(((void *)0), " ");
            printf("ARG1 : %s\n", arg1);
            arg2 = strtok(((void *)0), " ");
            printf("ARG2 : %s\n", arg2);
            arg3 = strtok(((void *)0), " ");
            printf("ARG3 : %s\n", arg3);
            i++;
        }
    }
    return 0;
}

variable_types:
line
char *

variable_types:
buff
unsigned int []

variable_types:
instr
char *

variable_types:
cmd
char *

variable_types:
reg
char *

variable_types:
val
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
parse_file(argv[1]);
generate_bin(&bytecode_buff, 0x10uLL, "./test.yex");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1(argv[1]);
func2(&bytecode_buff, 0x10uLL, "./test.yex");
return 0;
}

original_code:
int main(int argc, char* argv[]) {
    parse_file(argv[1]);
    int size = sizeof(bytecode_buff);
    generate_bin(bytecode_buff, size, "./test.yex");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    parse_file(argv[1]);
    int size = sizeof(bytecode_buff);
    generate_bin(bytecode_buff, size, "./test.yex");
    return 0;
}

variable_types: size int


repo: twinshadow/progcee

decompiled_code:
_QWORD *oaddr_new()
{
_QWORD *v0; // rbx
_QWORD *v1; // rbp
_QWORD *v2; // rax

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = calloc(0x10uLL, 1uLL);
v0[1] = v1;
v2 = calloc(0x10uLL, 1uLL);
v0[2] = v2;
*v1 = 0LL;
v1[1] = 0LL;
*v2 = 0LL;
v2[1] = 0LL;
}
return v0;
}

canonical_decompiled_code:
_QWORD *func6()
{
_QWORD *v0; // rbx
_QWORD *v1; // rbp
_QWORD *v2; // rax

v0 = calloc(1uLL, 0x18uLL);
if ( v0 )
{
v1 = calloc(0x10uLL, 1uLL);
v0[1] = v1;
v2 = calloc(0x10uLL, 1uLL);
v0[2] = v2;
*v1 = 0LL;
v1[1] = 0LL;
*v2 = 0LL;
v2[1] = 0LL;
}
return v0;
}

original_code:
struct oaddr_t *
oaddr_new()
{
 struct oaddr_t *oax;
 oax = calloc(1, sizeof(struct oaddr_t));
 if(oax == ((void *)0))
  return ((void *)0);
 oax->address = calloc(16, sizeof(unsigned char));
 oax->netmask = calloc(16, sizeof(unsigned char));
 memset(oax->address, 0x0, 16);
 memset(oax->netmask, 0x0, 16);
 return oax;
}

canonical_original_code:
struct oaddr_t *oaddr_new()
{
 struct oaddr_t *oax;
 oax = calloc(1, sizeof(struct oaddr_t));
 if(oax == ((void *)0))
  return ((void *)0);
 oax->address = calloc(16, sizeof(unsigned char));
 oax->netmask = calloc(16, sizeof(unsigned char));
 memset(oax->address, 0x0, 16);
 memset(oax->netmask, 0x0, 16);
 return oax;
}

variable_types: struct oaddr_t { int length; int address_family; unsigned char *address; unsigned char *netmask; } *


decompiled_code:
__int64 __fastcall oaddr_free(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *ptr)
{
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}
return 0LL;
}

original_code:
int
oaddr_free(struct oaddr_t *oa)
{
 if(oa == ((void *)0))
  return 0;
 free(oa->address);
 free(oa->netmask);
 free(oa);
 return(0);
}

user_defined_types: struct oaddr_t { int length; int address_family; unsigned char *address; unsigned char *netmask; }


decompiled_code:
__int64 __fastcall oaddr_isbad(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)(*a1 > 3) + 1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
__int64 result; // rax

if ( a1 )
result = (unsigned int)(*a1 > 3) + 1;
else
result = 0LL;
return result;
}

original_code:
int
oaddr_isbad(struct oaddr_t *oa)
{
 if(oa == ((void *)0))
  return OADDR_NULL;
 if(oa->length < 4)
  return OADDR_TOOSMALL;
 if(oa->address_family != 10 || oa->address_family != 2)
  return OADDR_BADAF;
 if(oa->address == ((void *)0))
  return OADDR_NOADDR;
 if(oa->netmask == ((void *)0))
  return OADDR_NOMASK;
 return 0;
}


original_code:
int
in_network(struct oaddr_t *oa, struct oaddr_t *subnet)
{
 if(oaddr_isbad(oa) || oaddr_isbad(subnet))
  return -1;
 int i;
 for(i = subnet->length - 1; i >= 0; i--)
 {
  if(subnet->netmask[i] == '\0')
   continue;
  if(oa->address[i] >= (subnet->netmask[i] & subnet->address[i]) &&
     oa->address[i] <= (subnet->address[i] | ((~subnet->netmask[i]) & 0xFF)))
   continue;
  else
   return(0);
 }
 return(1);
}

variable_types:
subnet
struct oaddr_t *


decompiled_code:
__int64 __fastcall ipcalc_pton(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebx
int v7; // eax

v4 = -1;
if ( a2 )
{
v4 = oaddr_isbad(a3, a2, a3, a4);
if ( v4 )
{
v4 = -1;
}
else
{
v7 = inet_pton(*(_DWORD *)(a3 + 4), a2, *(void **)(a3 + 8));
if ( v7 <= 0 )
{
if ( v7 )
perror("inet_pton");
else
fprintf(stderr, "Not in presentation format: %s", a2);
v4 = 1;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebx
int v7; // eax

v4 = -1;
if ( a2 )
{
v4 = func8(a3, a2, a3, a4);
if ( v4 )
{
v4 = -1;
}
else
{
v7 = inet_pton(*(_DWORD *)(a3 + 4), a2, *(void **)(a3 + 8));
if ( v7 <= 0 )
{
if ( v7 )
perror("inet_pton");
else
fprintf(stderr, "Not in presentation format: %s", a2);
v4 = 1;
}
}
}
return v4;
}

original_code:
int
ipcalc_pton(int af, const char *str, struct oaddr_t *oa)
{
 if(str == ((void *)0))
  return -1;
 if(oaddr_isbad(oa))
  return -1;
 int s = inet_pton(oa->address_family, str, oa->address);
 if (s <= 0)
 {
  if (s == 0)
   fprintf(stderr, "Not in presentation format: %s", str);
  else
   perror("inet_pton");
  return(1);
 }
 return(0);
}

canonical_original_code:
int ipcalc_pton(int af, char *str, struct oaddr_t *oa)
{
 if(str == ((void *)0))
  return -1;
 if(oaddr_isbad(oa))
  return -1;
 int s = inet_pton(oa->address_family, str, oa->address);
 if (s <= 0)
 {
  if (s == 0)
   fprintf(stderr, "Not in presentation format: %s", str);
  else
   perror("inet_pton");
  return(1);
 }
 return(0);
}

variable_types: af int

variable_types:
str
char *

variable_types: s int


decompiled_code:
__int64 __fastcall oaddr_ntop(__int64 a1, char *a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebx

v4 = -1;
if ( a2 )
{
v4 = oaddr_isbad(a1, a2, a3, a4);
if ( v4 )
{
v4 = -1;
}
else if ( !inet_ntop(*(_DWORD *)(a1 + 4), *(const void **)(a1 + 8), a2, 0x2Eu) )
{
perror("oaddr_ntop");
v4 = 1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, char *a2, __int64 a3, __int64 a4)
{
unsigned int v4; // ebx

v4 = -1;
if ( a2 )
{
v4 = func8(a1, a2, a3, a4);
if ( v4 )
{
v4 = -1;
}
else if ( !inet_ntop(*(_DWORD *)(a1 + 4), *(const void **)(a1 + 8), a2, 0x2Eu) )
{
perror("oaddr_ntop");
v4 = 1;
}
}
return v4;
}

original_code:
int
oaddr_ntop(struct oaddr_t *oa, char *str)
{
 if(str == ((void *)0))
  return -1;
 if(oaddr_isbad(oa))
  return -1;
 if (inet_ntop(oa->address_family, oa->address, str, 46) == ((void *)0))
 {
  perror("oaddr_ntop");
  return(1);
 }
 return(0);
}


decompiled_code:
__int64 __fastcall oaddr_decr(int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v5; // edx

result = oaddr_isbad(a1, a2, a3, a4);
if ( !(_DWORD)result )
{
v5 = *a1;
result = (unsigned int)(*a1 - 1);
if ( *a1 - 1 >= 0 )
{
result = (int)result;
do
{
if ( --*(_BYTE *)(*((_QWORD *)a1 + 1) + result) )
break;
--result;
}
while ( result != v5 - 2LL - (unsigned int)(v5 - 1) );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v5; // edx

result = func8(a1, a2, a3, a4);
if ( !(_DWORD)result )
{
v5 = *a1;
result = (unsigned int)(*a1 - 1);
if ( *a1 - 1 >= 0 )
{
result = (int)result;
do
{
if ( --*(_BYTE *)(*((_QWORD *)a1 + 1) + result) )
break;
--result;
}
while ( result != v5 - 2LL - (unsigned int)(v5 - 1) );
}
}
return result;
}

original_code:
void
oaddr_decr(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return;
 int i;
 for(i = oa->length - 1; i >= 0; i--)
 {
  oa->address[i]--;
  if(oa->address[i] != 0x0)
   break;
 }
}


decompiled_code:
__int64 __fastcall oaddr_incr(int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v5; // edx

result = oaddr_isbad(a1, a2, a3, a4);
if ( !(_DWORD)result )
{
v5 = *a1;
result = (unsigned int)(*a1 - 1);
if ( *a1 - 1 >= 0 )
{
result = (int)result;
do
{
if ( ++*(_BYTE *)(*((_QWORD *)a1 + 1) + result) != 0xFF )
break;
--result;
}
while ( result != v5 - 2LL - (unsigned int)(v5 - 1) );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(int *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
int v5; // edx

result = func8(a1, a2, a3, a4);
if ( !(_DWORD)result )
{
v5 = *a1;
result = (unsigned int)(*a1 - 1);
if ( *a1 - 1 >= 0 )
{
result = (int)result;
do
{
if ( ++*(_BYTE *)(*((_QWORD *)a1 + 1) + result) != 0xFF )
break;
--result;
}
while ( result != v5 - 2LL - (unsigned int)(v5 - 1) );
}
}
return result;
}

original_code:
void
oaddr_incr(struct oaddr_t *oa)
{
 if(oaddr_isbad(oa))
  return;
 int i;
 for(i = oa->length - 1; i >= 0; i--)
 {
  oa->address[i]++;
  if(oa->address[i] != 0xFF)
   break;
 }
}