playercmp

decompiled_code:
int __fastcall playercmp(const void *a1, const void *a2)
{
char v2; // al
int result; // eax

v2 = *(_BYTE *)a2;
if ( !*(_BYTE *)a1 )
return v2 != 0;
if ( !v2 )
return -1;
result = strncmp((const char *)a1, (const char *)a2, 0xAuLL);
if ( !result )
result = strncmp((const char *)a1 + 10, (const char *)a2 + 10, 8uLL);
return result;
}

canonical_decompiled_code:
int __fastcall func7(const void *a1, const void *a2)
{
char v2; // al
int result; // eax

v2 = *(_BYTE *)a2;
if ( !*(_BYTE *)a1 )
return v2 != 0;
if ( !v2 )
return -1;
result = strncmp((const char *)a1, (const char *)a2, 0xAuLL);
if ( !result )
result = strncmp((const char *)a1 + 10, (const char *)a2 + 10, 8uLL);
return result;
}

original_code:
static int playercmp( const void *arg1, const void *arg2 )
{
     const fileplayer_s *p1 = (fileplayer_s *)arg1;
     const fileplayer_s *p2 = (fileplayer_s *)arg2;
           int cmp;
     if ( p1->last_name[0] == '\0' )
     {
          if ( p2->last_name[0] == '\0' ) return 0;
          return 1;
     }
     if ( p2->last_name[0] == '\0' ) return -1;
     if ( (cmp = strncmp( p1->last_name, p2->last_name, sizeof(p1->last_name) )) != 0 ) return cmp;
     return strncmp( p1->first_name, p2->first_name, sizeof(p1->first_name) );
}

canonical_original_code:
static int playercmp(void *arg1, void *arg2)
{
     struct fileplayer_s *p1 = (fileplayer_s *)arg1;
     struct fileplayer_s *p2 = (fileplayer_s *)arg2;
           int cmp;
     if ( p1->last_name[0] == '\0' )
     {
          if ( p2->last_name[0] == '\0' ) return 0;
          return 1;
     }
     if ( p2->last_name[0] == '\0' ) return -1;
     if ( (cmp = strncmp( p1->last_name, p2->last_name, sizeof(p1->last_name) )) != 0 ) return cmp;
     return strncmp( p1->first_name, p2->first_name, sizeof(p1->first_name) );
}

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } action; struct acc_bat_stats_s simulated; } filebatting; struct pitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } action; struct acc_pch_stats_s simulated; } filepitching; } filestats; } *

variable_types: cmp int

user_defined_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct batting_s filebatting; struct pitching_s filepitching; } filestats; }

user_defined_types: struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s action; struct acc_bat_stats_s simulated; }

user_defined_types: struct pitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_pch_stats_s action; struct acc_pch_stats_s simulated; }


main

canonical_name: main

repo: zjentohlauedy/MBA

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // rbp
int v5; // er8
int result; // eax

if ( argc <= 2 )
{
printf("Usage: %s <input file> <output file>\n", *argv);
result = 0;
}
else
{
v3 = (void *)readPlayersFile((char *)argv[1]);
v4 = v3;
if ( v3 )
{
qsort(v3, 0x320uLL, 0x70uLL, playercmp);
v5 = writePlayersFile(argv[2], v4);
result = 0;
if ( !v5 )
{
puts("Cannot save player changes.");
result = 1;
}
}
else
{
printf("Unable to load players file <%s>.\n", argv[1]);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rax
void *v4; // rbp
int v5; // er8
int result; // eax

if ( argc <= 2 )
{
printf("Usage: %s <input file> <output file>\n", *argv);
result = 0;
}
else
{
v3 = (void *)func17((char *)argv[1]);
v4 = v3;
if ( v3 )
{
qsort(v3, 0x320uLL, 0x70uLL, playercmp);
v5 = func18(argv[2], v4);
result = 0;
if ( !v5 )
{
puts("Cannot save player changes.");
result = 1;
}
}
else
{
printf("Unable to load players file <%s>.\n", argv[1]);
result = 0;
}
}
return result;
}

original_code:
int main( const int argc, const char *argv[] )
{
     fileplayer_s *playersFile;
     int idx;
     if ( argc < 3 )
     {
   printf( "Usage: %s <input file> <output file>\n", argv[0] );
   return 0;
     }
     if ( (playersFile = readPlayersFile( argv[1] )) == ((void *)0) )
     {
          printf( "Unable to load players file <%s>.\n", argv[1] );
          return 0;
     }
     qsort( playersFile, (((25 * 8) * 2) * 2), sizeof(fileplayer_s), playercmp );
     if ( ! writePlayersFile( argv[2], playersFile ) )
     {
          printf( "Cannot save player changes.\n" );
          return 1;
     }
     return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
     struct fileplayer_s *playersFile;
     int idx;
     if ( argc < 3 )
     {
   printf( "Usage: %s <input file> <output file>\n", argv[0] );
   return 0;
     }
     if ( (playersFile = readPlayersFile( argv[1] )) == ((void *)0) )
     {
          printf( "Unable to load players file <%s>.\n", argv[1] );
          return 0;
     }
     qsort( playersFile, (((25 * 8) * 2) * 2), sizeof(fileplayer_s), playercmp );
     if ( ! writePlayersFile( argv[2], playersFile ) )
     {
          printf( "Cannot save player changes.\n" );
          return 1;
     }
     return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: idx int

return_type: int

user_defined_types: struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; }

user_defined_types: struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; }


buildIntoDivision

decompiled_code:
int __fastcall buildIntoDivision(__int64 a1, unsigned int a2)
{
*(_DWORD *)a1 = a2;
return sprintf((char *)(a1 + 4), "Division%d", a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2)
{
*(_DWORD *)a1 = a2;
return sprintf((char *)(a1 + 4), "Division%d", a2);
}

original_code:
void buildIntoDivision( division_s *division, const int division_id )
{
     division->division_id = division_id;
     sprintf( division->name, "Division%d", division_id );
}

canonical_original_code:
void buildIntoDivision(struct division_s *division, int division_id)
{
     division->division_id = division_id;
     sprintf( division->name, "Division%d", division_id );
}

variable_types: struct division_s { int division_id; char name[-1]; struct division_team_s { int division_id; int team_id; struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } primary_color; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } secondary_color; struct team_player_s { int team_id; int season; int player_id; struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e { st_None=0, st_Light=1, st_Dark=2 } skin_tone; enum handedness_e { hnd_None=0, hnd_Right=1, hnd_Left=2, hnd_Switch=3 } handedness; enum playertype_e { pt_None=0, pt_Pitcher=1, pt_Batter=2 } player_type; int rookie_season; int longevity; struct player_accolade_s { int player_id; int season; enum accolade_e { acc_None=0, acc_All_Star=1, acc_World_Title=2, acc_League_Title=3, acc_Division_Title=4, acc_Best_Record=5, acc_World_Series_MVP=6, acc_All_Star_Champion=7, acc_All_Star_MVP=8 } accolade; } *accolades; union { struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *pitching; struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *batting; } details; } *player; } *players; struct team_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct team_versus_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; } *versus_stats; struct team_pitching_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *pitching_stats; struct team_batting_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *batting_stats; struct team_accolade_s { int team_id; int season; enum team_accolade_e { tacc_None=0, tacc_World_Title=1, tacc_League_Title=2, tacc_Division_Title=3, tacc_Best_Record=4, tacc_All_Star_Champion=5 } accolade; } *accolades; } *team; } *teams; struct division_stats_s { int division_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct division_accolade_s { int division_id; int season; enum division_accolade_e { dacc_None=0, dacc_World_Title=1, dacc_League_Title=2, dacc_Best_Record=3 } accolade; } *accolades; } *

return_type: void

user_defined_types: struct division_s { int division_id; char name[-1]; struct division_team_s *teams; struct division_stats_s *stats; struct division_accolade_s *accolades; }

user_defined_types: struct division_team_s { int division_id; int team_id; struct team_s *team; }

user_defined_types: struct division_stats_s { int division_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct division_accolade_s { int division_id; int season; enum division_accolade_e accolade; }

user_defined_types: struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e primary_color; enum color_e secondary_color; struct team_player_s *players; struct team_stats_s *stats; struct team_versus_stats_s *versus_stats; struct team_pitching_stats_s *pitching_stats; struct team_batting_stats_s *batting_stats; struct team_accolade_s *accolades; }

user_defined_types: struct team_player_s { int team_id; int season; int player_id; struct player_s *player; }

user_defined_types: struct team_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_versus_stats_s { int team_id; int season; enum season_phase_e season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_pitching_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct team_batting_stats_s { int team_id; int season; enum season_phase_e season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; }

user_defined_types: struct team_accolade_s { int team_id; int season; enum team_accolade_e accolade; }

user_defined_types: struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e skin_tone; enum handedness_e handedness; enum playertype_e player_type; int rookie_season; int longevity; struct player_accolade_s *accolades; union { struct pitcher_s *pitching; struct batter_s *batting; } details; }

user_defined_types: struct player_accolade_s { int player_id; int season; enum accolade_e accolade; }

user_defined_types: struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s *stats; struct pitcher_accolade_s *accolades; }

user_defined_types: struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e primary_position; enum position_e secondary_position; struct batter_stats_s *stats; struct batter_accolade_s *accolades; }

user_defined_types: struct pitcher_stats_s { int player_id; int season; enum season_phase_e season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e accolade; }

user_defined_types: struct batter_stats_s { int player_id; int season; enum season_phase_e season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; }

user_defined_types: struct batter_accolade_s { int player_id; int season; enum batting_accolade_e accolade; }


buildFileParks

decompiled_code:
void *buildFileParks()
{
char *v0; // rbp
unsigned int i; // ebx
char *v2; // rdi

v0 = s;
for ( i = 0; i != 32; sprintf(v2, "Park%d", i) )
{
++i;
v2 = v0;
v0 += 16;
}
return &parks_data_0;
}

canonical_decompiled_code:
void *func0()
{
char *v0; // rbp
unsigned int i; // ebx
char *v2; // rdi

v0 = s;
for ( i = 0; i != 32; sprintf(v2, "Park%d", i) )
{
++i;
v2 = v0;
v0 += 16;
}
return &parks_data_0;
}

original_code:
fileparks_s *buildFileParks( void )
{
     static fileparks_s parks_data = { 0 };
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          sprintf( parks_data.park_names[i].text, "Park%d", i + 1 );
     }
     return &parks_data;
}

canonical_original_code:
struct fileparks_s *buildFileParks()
{
     static struct fileparks_s parks_data = { 0 };
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          sprintf( parks_data.park_names[i].text, "Park%d", i + 1 );
     }
     return &parks_data;
}

variable_types: i int

return_type: struct fileparks_s { unsigned char filler[52]; struct park_name_s { unsigned char text[16]; } park_names[32]; struct park_details_s { unsigned char details1[1]; unsigned char bleachers[1]; unsigned char details2[2]; struct distances_s { unsigned char left_line[2]; unsigned char left_center[2]; unsigned char center[2]; unsigned char right_center[2]; unsigned char right_line[2]; } distances; struct heights_s { unsigned char left1[1]; unsigned char left2[1]; unsigned char left3[1]; unsigned char left4[1]; unsigned char center[1]; unsigned char right4[1]; unsigned char right3[1]; unsigned char right2[1]; unsigned char right1[1]; } heights; unsigned char empty[1]; struct coords_s { char x[2]; char y[2]; } outfield[10]; struct coords_s infield1[8]; struct coords_s infield2[8]; } park_details[32]; } *

user_defined_types: struct fileparks_s { unsigned char filler[52]; struct park_name_s park_names[32]; struct park_details_s park_details[32]; }

user_defined_types: struct park_details_s { unsigned char details1[1]; unsigned char bleachers[1]; unsigned char details2[2]; struct distances_s distances; struct heights_s heights; unsigned char empty[1]; struct coords_s outfield[10]; struct coords_s infield1[8]; struct coords_s infield2[8]; }


clearErrorMessage

decompiled_code:
void clearErrorMessage()
{
error_message = 0;
}

canonical_decompiled_code:
void func0()
{
error_message = 0;
}

original_code:
static void clearErrorMessage( void )
{
     error_message[0] = '\0';
}

canonical_original_code:
static void clearErrorMessage()
{
     error_message[0] = '\0';
}


getCopyLongevityError

decompiled_code:
char *getCopyLongevityError()
{
return &error_message;
}

canonical_decompiled_code:
char *func1()
{
return &error_message;
}

original_code:
char *getCopyLongevityError( void )
{
     return error_message;
}

canonical_original_code:
char *getCopyLongevityError()
{
     return error_message;
}

return_type: char *


copyLongevity

decompiled_code:
__int64 __fastcall copyLongevity(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rbx

v2 = a1;
clearErrorMessage();
do
{
if ( *(_BYTE *)v2 )
{
v3 = findMatchingPlayer(v2, a2);
if ( !v3 )
{
sprintf(&error_message, "Player <%.*s, %.*s> not found!", 10, (const char *)v2, 8, (const char *)(v2 + 10));
return 0LL;
}
if ( (unsigned int)nibble(*(unsigned __int8 *)(v2 + 47), 1LL) )
*(_BYTE *)(v2 + 50) = *(_BYTE *)(v3 + 50);
}
v2 += 112LL;
}
while ( v2 != a1 + 89600 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rbx

v2 = a1;
func0();
do
{
if ( *(_BYTE *)v2 )
{
v3 = findMatchingPlayer(v2, a2);
if ( !v3 )
{
sprintf(&error_message, "Player <%.*s, %.*s> not found!", 10, (const char *)v2, 8, (const char *)(v2 + 10));
return 0LL;
}
if ( (unsigned int)nibble(*(unsigned __int8 *)(v2 + 47), 1LL) )
*(_BYTE *)(v2 + 50) = *(_BYTE *)(v3 + 50);
}
v2 += 112LL;
}
while ( v2 != a1 + 89600 );
return 1LL;
}

original_code:
boolean_e copyLongevity( fileplayer_s *players_file1, fileplayer_s *players_file2 )
{
     fileplayer_s *matchingPlayer;
     clearErrorMessage();
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( (players_file1[i].last_name)[0] == '\0' ) continue;
          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == ((void *)0) )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          int pos = nibble( players_file1[i].position[0], n_High );
          if ( pos != fpos_Pitcher )
          {
               players_file1[i].filestats.filebatting.ratings[2] = matchingPlayer->filestats.filebatting.ratings[2];
          }
     }
     return bl_True;
}

canonical_original_code:
enum boolean_e copyLongevity(struct fileplayer_s *players_file1, struct fileplayer_s *players_file2)
{
     struct fileplayer_s *matchingPlayer;
     clearErrorMessage();
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( (players_file1[i].last_name)[0] == '\0' ) continue;
          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == ((void *)0) )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name), players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );
               return bl_False;
          }
          int pos = nibble( players_file1[i].position[0], n_High );
          if ( pos != fpos_Pitcher )
          {
               players_file1[i].filestats.filebatting.ratings[2] = matchingPlayer->filestats.filebatting.ratings[2];
          }
     }
     return bl_True;
}

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; } filebatting; struct filepitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; } filepitching; } filestats; struct acc_stats_s { union acc_stats_u { struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } pitching; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } batting; struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } id_info; } action; union acc_stats_u simulated; } acc_stats; } *

variable_types: pos int

return_type: enum boolean_e { bl_False=0, bl_True=1 }

user_defined_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct filebatting_s filebatting; struct filepitching_s filepitching; } filestats; struct acc_stats_s acc_stats; }

user_defined_types: struct acc_stats_s { union acc_stats_u action; union acc_stats_u simulated; }

user_defined_types: union acc_stats_u { struct acc_pch_stats_s pitching; struct acc_bat_stats_s batting; struct acc_player_id_s id_info; }


buildIntoLeague

decompiled_code:
int __fastcall buildIntoLeague(__int64 a1, unsigned int a2)
{
*(_DWORD *)a1 = a2;
return sprintf((char *)(a1 + 4), "League%d", a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2)
{
*(_DWORD *)a1 = a2;
return sprintf((char *)(a1 + 4), "League%d", a2);
}

original_code:
void buildIntoLeague( league_s *league, const int league_id )
{
     league->league_id = league_id;
     sprintf( league->name, "League%d", league_id );
}

canonical_original_code:
void buildIntoLeague(struct league_s *league, int league_id)
{
     league->league_id = league_id;
     sprintf( league->name, "League%d", league_id );
}

variable_types: struct league_s { int league_id; char name[-1]; struct league_division_s { int league_id; int division_id; struct division_s { int division_id; char name[-1]; struct division_team_s { int division_id; int team_id; struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } primary_color; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } secondary_color; struct team_player_s { int team_id; int season; int player_id; struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e { st_None=0, st_Light=1, st_Dark=2 } skin_tone; enum handedness_e { hnd_None=0, hnd_Right=1, hnd_Left=2, hnd_Switch=3 } handedness; enum playertype_e { pt_None=0, pt_Pitcher=1, pt_Batter=2 } player_type; int rookie_season; int longevity; struct player_accolade_s { int player_id; int season; enum accolade_e { acc_None=0, acc_All_Star=1, acc_World_Title=2, acc_League_Title=3, acc_Division_Title=4, acc_Best_Record=5, acc_World_Series_MVP=6, acc_All_Star_Champion=7, acc_All_Star_MVP=8 } accolade; } *accolades; union { struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *pitching; struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *batting; } details; } *player; } *players; struct team_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct team_versus_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; } *versus_stats; struct team_pitching_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *pitching_stats; struct team_batting_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *batting_stats; struct team_accolade_s { int team_id; int season; enum team_accolade_e { tacc_None=0, tacc_World_Title=1, tacc_League_Title=2, tacc_Division_Title=3, tacc_Best_Record=4, tacc_All_Star_Champion=5 } accolade; } *accolades; } *team; } *teams; struct division_stats_s { int division_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct division_accolade_s { int division_id; int season; enum division_accolade_e { dacc_None=0, dacc_World_Title=1, dacc_League_Title=2, dacc_Best_Record=3 } accolade; } *accolades; } *division; } *divisions; struct league_team_s { int league_id; int team_id; struct team_s *team; } *teams; struct league_stats_s { int league_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int runs_scored; int runs_allowed; } *stats; struct league_accolade_s { int league_id; int season; enum league_accolade_e { lacc_None=0, lacc_World_Title=1, lacc_Best_Record=2, lacc_All_Star_Champion=3 } accolade; } *accolades; } *

user_defined_types: struct league_s { int league_id; char name[-1]; struct league_division_s *divisions; struct league_team_s *teams; struct league_stats_s *stats; struct league_accolade_s *accolades; }

user_defined_types: struct league_division_s { int league_id; int division_id; struct division_s *division; }

user_defined_types: struct league_stats_s { int league_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct league_accolade_s { int league_id; int season; enum league_accolade_e accolade; }

user_defined_types: struct division_s { int division_id; char name[-1]; struct division_team_s *teams; struct division_stats_s *stats; struct division_accolade_s *accolades; }

user_defined_types: struct division_team_s { int division_id; int team_id; struct team_s *team; }

user_defined_types: struct division_stats_s { int division_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct division_accolade_s { int division_id; int season; enum division_accolade_e accolade; }

user_defined_types: struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e primary_color; enum color_e secondary_color; struct team_player_s *players; struct team_stats_s *stats; struct team_versus_stats_s *versus_stats; struct team_pitching_stats_s *pitching_stats; struct team_batting_stats_s *batting_stats; struct team_accolade_s *accolades; }

user_defined_types: struct team_player_s { int team_id; int season; int player_id; struct player_s *player; }

user_defined_types: struct team_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_versus_stats_s { int team_id; int season; enum season_phase_e season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; }


formatAmigaToDos

original_code:
void formatAmigaToDos( fileplayer_s *players_file )
{
     for ( int idx = 0; idx < (((25 * 8) * 2) * 2); ++idx )
     {
   if ( (players_file[idx].last_name)[0] == '\0' ) continue;
          int pos = nibble( players_file[idx].position[0], n_High );
          acc_stats_s *acc_stats = &(players_file[idx].acc_stats);
          if ( pos != fpos_Pitcher )
          {
               capStat( acc_stats->simulated.batting.acc_rbi, acc_stats->action.batting.acc_rbi );
               capStat( acc_stats->simulated.batting.acc_so, acc_stats->action.batting.acc_so );
               acc_stats_u act = acc_stats->action;
               acc_stats->action = acc_stats->simulated;
               acc_stats->simulated = act;
          }
          else
          {
               unsigned char games = byte2int( acc_stats->simulated.pitching.acc_starts );
               int2byte( acc_stats->simulated.pitching.acc_starts, 0 );
               int2byte( acc_stats->action. batting. acc_games, games );
          }
     }
}

canonical_original_code:
void formatAmigaToDos(struct fileplayer_s *players_file)
{
     for ( int idx = 0; idx < (((25 * 8) * 2) * 2); ++idx )
     {
   if ( (players_file[idx].last_name)[0] == '\0' ) continue;
          int pos = nibble( players_file[idx].position[0], n_High );
          struct acc_stats_s *acc_stats = &(players_file[idx].acc_stats);
          if ( pos != fpos_Pitcher )
          {
               capStat( acc_stats->simulated.batting.acc_rbi, acc_stats->action.batting.acc_rbi );
               capStat( acc_stats->simulated.batting.acc_so, acc_stats->action.batting.acc_so );
               union acc_stats_u act = acc_stats->action;
               acc_stats->action = acc_stats->simulated;
               acc_stats->simulated = act;
          }
          else
          {
               unsigned char games = byte2int( acc_stats->simulated.pitching.acc_starts );
               int2byte( acc_stats->simulated.pitching.acc_starts, 0 );
               int2byte( acc_stats->action. batting. acc_games, games );
          }
     }
}

variable_types: struct acc_stats_s { union acc_stats_u { struct acc_pch_stats_s { unsigned char acc_wins[1]; unsigned char acc_losses[1]; unsigned char acc_starts[1]; unsigned char acc_saves[1]; unsigned char acc_innings[2]; unsigned char acc_hits[2]; unsigned char acc_er[2]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[2]; } pitching; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } batting; struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } id_info; } action; union acc_stats_u simulated; } *

variable_types:
games
unsigned char

user_defined_types: struct filebatting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; }

user_defined_types: struct filepitching_s { unsigned char ratings[2]; unsigned char real_wins[1]; unsigned char real_losses[1]; unsigned char real_games[1]; unsigned char real_starts[1]; unsigned char real_cg[1]; unsigned char real_saves[1]; unsigned char real_inn[2]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[2]; unsigned char real_er[1]; unsigned char real_fa[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[2]; unsigned char real_hb[1]; unsigned char real_balk[1]; unsigned char real_ab[1]; unsigned char real_hits[1]; unsigned char real_hr[1]; unsigned char real_sh[1]; unsigned char injury_days[1]; unsigned char color[1]; }


buildIntoTeam

decompiled_code:
int __fastcall buildIntoTeam(__int64 a1, unsigned int a2)
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 48) = rand() % 8 + 1;
*(_DWORD *)(a1 + 52) = rand() % 8 + 1;
sprintf((char *)(a1 + 4), "Team%d", a2);
return sprintf((char *)(a1 + 25), "City%d", a2);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2)
{
*(_DWORD *)a1 = a2;
*(_DWORD *)(a1 + 48) = rand() % 8 + 1;
*(_DWORD *)(a1 + 52) = rand() % 8 + 1;
sprintf((char *)(a1 + 4), "Team%d", a2);
return sprintf((char *)(a1 + 25), "City%d", a2);
}

original_code:
void buildIntoTeam( team_s *team, const int team_id )
{
     team->team_id = team_id;
     team->primary_color = (rand() % 8) + 1;
     team->secondary_color = (rand() % 8) + 1;
     sprintf( team->name, "Team%d", team_id );
     sprintf( team->location, "City%d", team_id );
}

canonical_original_code:
void buildIntoTeam(struct team_s *team, int team_id)
{
     team->team_id = team_id;
     team->primary_color = (rand() % 8) + 1;
     team->secondary_color = (rand() % 8) + 1;
     sprintf( team->name, "Team%d", team_id );
     sprintf( team->location, "City%d", team_id );
}

variable_types: struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } primary_color; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } secondary_color; struct team_player_s { int team_id; int season; int player_id; struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e { st_None=0, st_Light=1, st_Dark=2 } skin_tone; enum handedness_e { hnd_None=0, hnd_Right=1, hnd_Left=2, hnd_Switch=3 } handedness; enum playertype_e { pt_None=0, pt_Pitcher=1, pt_Batter=2 } player_type; int rookie_season; int longevity; struct player_accolade_s { int player_id; int season; enum accolade_e { acc_None=0, acc_All_Star=1, acc_World_Title=2, acc_League_Title=3, acc_Division_Title=4, acc_Best_Record=5, acc_World_Series_MVP=6, acc_All_Star_Champion=7, acc_All_Star_MVP=8 } accolade; } *accolades; union { struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *pitching; struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *batting; } details; } *player; } *players; struct team_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct team_versus_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; } *versus_stats; struct team_pitching_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *pitching_stats; struct team_batting_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *batting_stats; struct team_accolade_s { int team_id; int season; enum team_accolade_e { tacc_None=0, tacc_World_Title=1, tacc_League_Title=2, tacc_Division_Title=3, tacc_Best_Record=4, tacc_All_Star_Champion=5 } accolade; } *accolades; } *

user_defined_types: struct team_pitching_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct team_batting_stats_s { int team_id; int season; enum season_phase_e season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; }

user_defined_types: struct team_accolade_s { int team_id; int season; enum team_accolade_e accolade; }

user_defined_types: struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e skin_tone; enum handedness_e handedness; enum playertype_e player_type; int rookie_season; int longevity; struct player_accolade_s *accolades; union { struct pitcher_s *pitching; struct batter_s *batting; } details; }

user_defined_types: struct player_accolade_s { int player_id; int season; enum accolade_e accolade; }

user_defined_types: struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s *stats; struct pitcher_accolade_s *accolades; }

user_defined_types: struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e primary_position; enum position_e secondary_position; struct batter_stats_s *stats; struct batter_accolade_s *accolades; }

user_defined_types: struct pitcher_stats_s { int player_id; int season; enum season_phase_e season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e accolade; }

user_defined_types: struct batter_stats_s { int player_id; int season; enum season_phase_e season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; }

user_defined_types: struct batter_accolade_s { int player_id; int season; enum batting_accolade_e accolade; }


buildTeam

decompiled_code:
void *__fastcall buildTeam(unsigned int a1)
{
void *v1; // rax
void *v2; // r12

v1 = calloc(0x68uLL, 1uLL);
v2 = v1;
if ( v1 )
buildIntoTeam((__int64)v1, a1);
return v2;
}

canonical_decompiled_code:
void *__fastcall func1(unsigned int a1)
{
void *v1; // rax
void *v2; // r12

v1 = calloc(0x68uLL, 1uLL);
v2 = v1;
if ( v1 )
func0((__int64)v1, a1);
return v2;
}

original_code:
team_s *buildTeam( const int team_id )
{
     team_s *team = ((void *)0);
     if ( (team = malloc( sizeof(team_s) )) == ((void *)0) ) return ((void *)0);
     memset( team, '\0', sizeof(team_s) );
     buildIntoTeam( team, team_id );
     return team;
}

canonical_original_code:
struct team_s *buildTeam(int team_id)
{
     struct team_s *team = ((void *)0);
     if ( (team = malloc( sizeof(team_s) )) == ((void *)0) ) return ((void *)0);
     memset( team, '\0', sizeof(team_s) );
     buildIntoTeam( team, team_id );
     return team;
}

return_type: struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } primary_color; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } secondary_color; struct team_player_s { int team_id; int season; int player_id; struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e { st_None=0, st_Light=1, st_Dark=2 } skin_tone; enum handedness_e { hnd_None=0, hnd_Right=1, hnd_Left=2, hnd_Switch=3 } handedness; enum playertype_e { pt_None=0, pt_Pitcher=1, pt_Batter=2 } player_type; int rookie_season; int longevity; struct player_accolade_s { int player_id; int season; enum accolade_e { acc_None=0, acc_All_Star=1, acc_World_Title=2, acc_League_Title=3, acc_Division_Title=4, acc_Best_Record=5, acc_World_Series_MVP=6, acc_All_Star_Champion=7, acc_All_Star_MVP=8 } accolade; } *accolades; union { struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *pitching; struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *batting; } details; } *player; } *players; struct team_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct team_versus_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; } *versus_stats; struct team_pitching_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *pitching_stats; struct team_batting_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *batting_stats; struct team_accolade_s { int team_id; int season; enum team_accolade_e { tacc_None=0, tacc_World_Title=1, tacc_League_Title=2, tacc_Division_Title=3, tacc_Best_Record=4, tacc_All_Star_Champion=5 } accolade; } *accolades; } *

user_defined_types: struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e primary_color; enum color_e secondary_color; struct team_player_s *players; struct team_stats_s *stats; struct team_versus_stats_s *versus_stats; struct team_pitching_stats_s *pitching_stats; struct team_batting_stats_s *batting_stats; struct team_accolade_s *accolades; }


cmpplr

decompiled_code:
int __fastcall cmpplr(const void *a1, const void *a2)
{
int v2; // eax
int v3; // edx
int result; // eax
int v5; // eax
int v6; // edx

v2 = *((_DWORD *)a1 + 2);
v3 = *((_DWORD *)a2 + 2);
if ( v2 != v3 )
return v2 - v3;
if ( v2 == 2 )
return 0;
if ( v2 == 1 )
{
v5 = *((_DWORD *)a1 + 16);
v6 = *((_DWORD *)a2 + 16);
if ( v5 != v6 )
return v5 - v6;
}
else if ( v2 )
{
return 0;
}
result = strcmp((const char *)a1 + 37, (const char *)a2 + 37);
if ( !result )
result = strcmp((const char *)a1 + 16, (const char *)a2 + 16);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, const void *a2)
{
int v2; // eax
int v3; // edx
int result; // eax
int v5; // eax
int v6; // edx

v2 = *((_DWORD *)a1 + 2);
v3 = *((_DWORD *)a2 + 2);
if ( v2 != v3 )
return v2 - v3;
if ( v2 == 2 )
return 0;
if ( v2 == 1 )
{
v5 = *((_DWORD *)a1 + 16);
v6 = *((_DWORD *)a2 + 16);
if ( v5 != v6 )
return v5 - v6;
}
else if ( v2 )
{
return 0;
}
result = strcmp((const char *)a1 + 37, (const char *)a2 + 37);
if ( !result )
result = strcmp((const char *)a1 + 16, (const char *)a2 + 16);
return result;
}

original_code:
static int cmpplr( const void *arg1, const void *arg2 )
{
     const player_s *p1 = (player_s *)arg1;
     const player_s *p2 = (player_s *)arg2;
           int cmp;
     if ( p1->type != p2->type ) return p1->type - p2->type;
     if ( p1->type == pt_None ) return 0;
     if ( p1->type == pt_Hitter )
     {
   const batter_s *b1 = &(p1->data.batter);
   const batter_s *b2 = &(p2->data.batter);
   if ( b1->primary_pos != b2->primary_pos ) return b1->primary_pos - b2->primary_pos;
   if ( (cmp = strcmp( b1->last_name, b2->last_name )) != 0 ) return cmp;
   return strcmp( b1->first_name, b2->first_name );
     }
     if ( p1->type == pt_Pitcher )
     {
   const pitcher_s *pt1 = &(p1->data.pitcher);
   const pitcher_s *pt2 = &(p2->data.pitcher);
   if ( (cmp = strcmp( pt1->last_name, pt2->last_name )) != 0 ) return cmp;
   return strcmp( pt1->first_name, pt2->first_name );
     }
     return 0;
}

canonical_original_code:
static int cmpplr(void *arg1, void *arg2)
{
     struct player_s *p1 = (player_s *)arg1;
     struct player_s *p2 = (player_s *)arg2;
           int cmp;
     if ( p1->type != p2->type ) return p1->type - p2->type;
     if ( p1->type == pt_None ) return 0;
     if ( p1->type == pt_Hitter )
     {
   struct batter_s *b1 = &(p1->data.batter);
   struct batter_s *b2 = &(p2->data.batter);
   if ( b1->primary_pos != b2->primary_pos ) return b1->primary_pos - b2->primary_pos;
   if ( (cmp = strcmp( b1->last_name, b2->last_name )) != 0 ) return cmp;
   return strcmp( b1->first_name, b2->first_name );
     }
     if ( p1->type == pt_Pitcher )
     {
   struct pitcher_s *pt1 = &(p1->data.pitcher);
   struct pitcher_s *pt2 = &(p2->data.pitcher);
   if ( (cmp = strcmp( pt1->last_name, pt2->last_name )) != 0 ) return cmp;
   return strcmp( pt1->first_name, pt2->first_name );
     }
     return 0;
}

variable_types: struct player_s { int player_id; int hand; enum playertype_e { pt_Pitcher=0, pt_Hitter=1, pt_None=2 } type; int injury_days; union { struct pitcher_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int speed; int control; int fatigue; int bunt; int longevity; struct pitching_s { int wins; int losses; int games; int games_started; int games_completed; int saves; float innings; int at_bats; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } potential; struct pitching_s simulated; float fielding_avg; } pitcher; struct batter_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int power; int hit_n_run; int bunt; int running; int range; int arm; int longevity; struct hitting_s { int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int rbi; int walks; int strike_outs; int stolen_bases; int errors; } potential; struct hitting_s simulated; struct fielding_s { int put_outs; int assists; int errors; float secondary_avg; } fielding; } batter; } data; } *

variable_types: struct batter_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int power; int hit_n_run; int bunt; int running; int range; int arm; int longevity; struct hitting_s { int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int rbi; int walks; int strike_outs; int stolen_bases; int errors; } potential; struct hitting_s simulated; struct fielding_s { int put_outs; int assists; int errors; float secondary_avg; } fielding; } *

variable_types: struct pitcher_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int speed; int control; int fatigue; int bunt; int longevity; struct pitching_s { int wins; int losses; int games; int games_started; int games_completed; int saves; float innings; int at_bats; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } potential; struct pitching_s simulated; float fielding_avg; } *

user_defined_types: struct player_s { int player_id; int hand; enum playertype_e type; int injury_days; union { struct pitcher_s pitcher; struct batter_s batter; } data; }

user_defined_types: struct batter_s { char first_name[-1]; char last_name[-1]; int year; enum position_e primary_pos; enum position_e secondary_pos; int power; int hit_n_run; int bunt; int running; int range; int arm; int longevity; struct hitting_s potential; struct hitting_s simulated; struct fielding_s fielding; }

user_defined_types: struct pitcher_s { char first_name[-1]; char last_name[-1]; int year; enum position_e primary_pos; enum position_e secondary_pos; int speed; int control; int fatigue; int bunt; int longevity; struct pitching_s potential; struct pitching_s simulated; float fielding_avg; }


convertFilesToLeagues

original_code:
league_s *convertFilesToLeagues( fileleague_s *leagueFile, const fileplayer_s *playerFile )
{
     league_s *leagues;
     int leag;
     int div;
     int team;
     int plyr;
     int idx;
     if ( (leagues = malloc( sizeof(league_s) * 2 )) == ((void *)0) )
     {
   printf( "Cannot allocate memory for leagues.\n" );
   return ((void *)0);
     }
     strcpy( leagues[0].name, leagueFile->league1 );
     strcpy( leagues[1].name, leagueFile->league2 );
     strcpy( leagues[0].divisions[0].name, leagueFile->division1 );
     strcpy( leagues[0].divisions[1].name, leagueFile->division2 );
     strcpy( leagues[1].divisions[0].name, leagueFile->division3 );
     strcpy( leagues[1].divisions[1].name, leagueFile->division4 );
     for ( leag = 0; leag < 2; ++leag )
     {
   for ( div = 0; div < 2; ++div )
   {
        for ( team = 0; team < 8; ++team )
        {
      idx = (leag * (8 * 2)) + (div * 8) + team;
      snprintf( leagues[leag].divisions[div].teams[team].name,
         sizeof(leagues[leag].divisions[div].teams[team].name),
         "%.*s",
         sizeof(leagueFile->teams[idx].name),
         leagueFile->teams[idx].name );
      leagues[leag].divisions[div].teams[team].wins = leagueFile->teams[idx].wins[0];
      leagues[leag].divisions[div].teams[team].losses = leagueFile->teams[idx].losses[0];
      leagues[leag].divisions[div].teams[team].color = leagueFile->teams[idx].color[0];
      for ( plyr = 0; plyr < 25; ++plyr )
      {
    idx = (leag * ((25 * 8) * 2)) + (div * (25 * 8)) + (team * 25) + plyr;
    copyPlayer( &leagues[leag].divisions[div].teams[team].players[plyr], &playerFile[idx] );
      }
      qsort( leagues[leag].divisions[div].teams[team].players, 25, sizeof(player_s), cmpplr );
        }
   }
     }
     return leagues;
}

canonical_original_code:
struct league_s *convertFilesToLeagues(struct fileleague_s *leagueFile, struct fileplayer_s *playerFile)
{
     struct league_s *leagues;
     int leag;
     int div;
     int team;
     int plyr;
     int idx;
     if ( (leagues = malloc( sizeof(league_s) * 2 )) == ((void *)0) )
     {
   printf( "Cannot allocate memory for leagues.\n" );
   return ((void *)0);
     }
     strcpy( leagues[0].name, leagueFile->league1 );
     strcpy( leagues[1].name, leagueFile->league2 );
     strcpy( leagues[0].divisions[0].name, leagueFile->division1 );
     strcpy( leagues[0].divisions[1].name, leagueFile->division2 );
     strcpy( leagues[1].divisions[0].name, leagueFile->division3 );
     strcpy( leagues[1].divisions[1].name, leagueFile->division4 );
     for ( leag = 0; leag < 2; ++leag )
     {
   for ( div = 0; div < 2; ++div )
   {
        for ( team = 0; team < 8; ++team )
        {
      idx = (leag * (8 * 2)) + (div * 8) + team;
      snprintf( leagues[leag].divisions[div].teams[team].name,
         sizeof(leagues[leag].divisions[div].teams[team].name),
         "%.*s",
         sizeof(leagueFile->teams[idx].name),
         leagueFile->teams[idx].name );
      leagues[leag].divisions[div].teams[team].wins = leagueFile->teams[idx].wins[0];
      leagues[leag].divisions[div].teams[team].losses = leagueFile->teams[idx].losses[0];
      leagues[leag].divisions[div].teams[team].color = leagueFile->teams[idx].color[0];
      for ( plyr = 0; plyr < 25; ++plyr )
      {
    idx = (leag * ((25 * 8) * 2)) + (div * (25 * 8)) + (team * 25) + plyr;
    copyPlayer( &leagues[leag].divisions[div].teams[team].players[plyr], &playerFile[idx] );
      }
      qsort( leagues[leag].divisions[div].teams[team].players, 25, sizeof(player_s), cmpplr );
        }
   }
     }
     return leagues;
}

variable_types: struct fileleague_s { unsigned char header[52]; unsigned char league1[12]; unsigned char league2[12]; unsigned char division1[12]; unsigned char division2[12]; unsigned char division3[12]; unsigned char division4[12]; struct fileteam_s { unsigned char name[12]; unsigned char color[1]; unsigned char wins[1]; unsigned char losses[1]; unsigned char term[1]; } teams[32]; } *

variable_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s { unsigned char acc_ab[2]; unsigned char acc_hits[2]; unsigned char acc_2b[1]; unsigned char acc_3b[1]; unsigned char acc_hr[1]; unsigned char acc_bb[1]; unsigned char acc_so[1]; unsigned char acc_games[1]; unsigned char acc_runs[1]; unsigned char acc_rbi[1]; unsigned char acc_sb[1]; unsigned char acc_err[1]; } action; struct acc_bat_stats_s simulated; } filebatting; struct pitching_s filepitching; } filestats; } *

variable_types: struct league_s { char name[-1]; struct division_s { char name[-1]; struct team_s { char name[-1]; int wins; int losses; enum color_e { cl_LtBlue=0, cl_Blue=1, cl_DkRed=2, cl_Red=3, cl_Gold=4, cl_Black=5, cl_Brown=6, cl_Green=7 } color; struct player_s { int player_id; int hand; enum playertype_e { pt_Pitcher=0, pt_Hitter=1, pt_None=2 } type; int injury_days; union { struct pitcher_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int speed; int control; int fatigue; int bunt; int longevity; struct pitching_s { int wins; int losses; int games; int games_started; int games_completed; int saves; float innings; int at_bats; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } potential; struct pitching_s simulated; float fielding_avg; } pitcher; struct batter_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int power; int hit_n_run; int bunt; int running; int range; int arm; int longevity; struct hitting_s { int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int rbi; int walks; int strike_outs; int stolen_bases; int errors; } potential; struct hitting_s simulated; struct fielding_s { int put_outs; int assists; int errors; float secondary_avg; } fielding; } batter; } data; } players[25]; } teams[8]; } divisions[2]; } *

variable_types: leag int

variable_types: div int

variable_types: team int

variable_types: plyr int

user_defined_types: struct fileleague_s { unsigned char header[52]; unsigned char league1[12]; unsigned char league2[12]; unsigned char division1[12]; unsigned char division2[12]; unsigned char division3[12]; unsigned char division4[12]; struct fileteam_s teams[32]; }

user_defined_types: struct fileplayer_s { char last_name[10]; char first_name[8]; char last_phoen[14]; char first_phoen[12]; unsigned char real_avg[2]; unsigned char year[1]; unsigned char position[1]; union { struct batting_s filebatting; struct pitching_s filepitching; } filestats; }

user_defined_types: struct league_s { char name[-1]; struct division_s divisions[2]; }

user_defined_types: struct batting_s { unsigned char ratings[4]; unsigned char real_games[1]; unsigned char real_runs[1]; unsigned char real_rbi[1]; unsigned char real_sb[1]; unsigned char real_cs[1]; unsigned char real_sh[1]; unsigned char vl_ab[2]; unsigned char vl_hits[2]; unsigned char vl_2b[1]; unsigned char vl_3b[1]; unsigned char vl_hr[1]; unsigned char vl_bb[1]; unsigned char vl_so[1]; unsigned char real_fa2[1]; unsigned char vr_ab[2]; unsigned char vr_hits[2]; unsigned char vr_2b[1]; unsigned char vr_3b[1]; unsigned char vr_hr[1]; unsigned char vr_bb[1]; unsigned char vr_so[1]; unsigned char real_err[1]; unsigned char real_po[2]; unsigned char real_as[2]; unsigned char injury_days[1]; unsigned char color[1]; struct acc_bat_stats_s action; struct acc_bat_stats_s simulated; }

user_defined_types: struct division_s { char name[-1]; struct team_s teams[8]; }

user_defined_types: struct team_s { char name[-1]; int wins; int losses; enum color_e color; struct player_s players[25]; }


generateFileLeagName

original_code:
fileleagname_s *generateFileLeagName( const org_s *org )
{
     fileleagname_s *league_file = ((void *)0);
     if ( (league_file = malloc( sizeof(fileleagname_s) )) == ((void *)0) ) return ((void *)0);
     memset( league_file, '\0', sizeof(fileleagname_s) );
     if ( org->leagues == ((void *)0) ) return league_file;
     for ( int i = 0; org->leagues[i].league != ((void *)0); ++i )
     {
          league_s *league = org->leagues[i].league;
          strcpy( league_file->leagues[i].name, league->name );
          for ( int j = 0; league->divisions[j].division != ((void *)0); ++j )
          {
               division_s *division = league->divisions[j].division;
               int div_idx = (i * 2) + j;
               strcpy( league_file->divisions[div_idx].name, division->name );
               for ( int k = 0; division->teams[k].team != ((void *)0); ++k )
               {
                    int team_idx = (i * (8 * 2)) + (j * 8) + k;
                    strcpy( league_file->teams[team_idx].name, division->teams[k].team->name );
                    int2byte( league_file->teams[team_idx].color, division->teams[k].team->primary_color );
                    int2byte( league_file->teams[team_idx].team_id, division->teams[k].team->team_id );
                    int2byte( league_file->teams[team_idx].stadium, team_idx );
               }
          }
     }
     return league_file;
}

canonical_original_code:
struct fileleagname_s *generateFileLeagName(struct org_s *org)
{
     struct fileleagname_s *league_file = ((void *)0);
     if ( (league_file = malloc( sizeof(fileleagname_s) )) == ((void *)0) ) return ((void *)0);
     memset( league_file, '\0', sizeof(fileleagname_s) );
     if ( org->leagues == ((void *)0) ) return league_file;
     for ( int i = 0; org->leagues[i].league != ((void *)0); ++i )
     {
          struct league_s *league = org->leagues[i].league;
          strcpy( league_file->leagues[i].name, league->name );
          for ( int j = 0; league->divisions[j].division != ((void *)0); ++j )
          {
               struct division_s *division = league->divisions[j].division;
               int div_idx = (i * 2) + j;
               strcpy( league_file->divisions[div_idx].name, division->name );
               for ( int k = 0; division->teams[k].team != ((void *)0); ++k )
               {
                    int team_idx = (i * (8 * 2)) + (j * 8) + k;
                    strcpy( league_file->teams[team_idx].name, division->teams[k].team->name );
                    int2byte( league_file->teams[team_idx].color, division->teams[k].team->primary_color );
                    int2byte( league_file->teams[team_idx].team_id, division->teams[k].team->team_id );
                    int2byte( league_file->teams[team_idx].stadium, team_idx );
               }
          }
     }
     return league_file;
}

variable_types: struct org_s { struct org_league_s { struct league_s { int league_id; char name[-1]; struct league_division_s { int league_id; int division_id; struct division_s { int division_id; char name[-1]; struct division_team_s { int division_id; int team_id; struct team_s { int team_id; char name[-1]; char location[-1]; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } primary_color; enum color_e { cl_None=0, cl_LtBlue=1, cl_Blue=2, cl_DkRed=3, cl_Red=4, cl_Gold=5, cl_Black=6, cl_Brown=7, cl_Green=8 } secondary_color; struct team_player_s { int team_id; int season; int player_id; struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e { st_None=0, st_Light=1, st_Dark=2 } skin_tone; enum handedness_e { hnd_None=0, hnd_Right=1, hnd_Left=2, hnd_Switch=3 } handedness; enum playertype_e { pt_None=0, pt_Pitcher=1, pt_Batter=2 } player_type; int rookie_season; int longevity; struct player_accolade_s { int player_id; int season; enum accolade_e { acc_None=0, acc_All_Star=1, acc_World_Title=2, acc_League_Title=3, acc_Division_Title=4, acc_Best_Record=5, acc_World_Series_MVP=6, acc_All_Star_Champion=7, acc_All_Star_MVP=8 } accolade; } *accolades; union { struct pitcher_s { int player_id; int speed; int control; int bunt; int fatigue; struct pitcher_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s { int innings; int outs; } innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *stats; struct pitcher_accolade_s { int player_id; int season; enum pitching_accolade_e { pacc_None=0, pacc_Pitcher_of_the_Year=1, pacc_Global_Pitcher_of_the_Year=2, pacc_World_Pitcher_of_the_Year=3, pacc_Atlantic_Pitcher_of_the_Year=4, pacc_North_Pitcher_of_the_Year=5, pacc_Pacific_Pitcher_of_the_Year=6, pacc_South_Pitcher_of_the_Year=7, pacc_Most_Wins=8, pacc_Best_Win_Loss_Ratio=9, pacc_Best_Win_Percentage=10, pacc_Best_Earned_Run_Average=11, pacc_Best_vs_Batting_Average=12, pacc_Most_Saves=13, pacc_Most_Strike_Outs=14, pacc_Most_Innings_per_Game=15, pacc_Best_Walks_Hits_Per_Inning=16, pacc_Most_Strike_Outs_per_Nine=17, pacc_Best_Home_Runs_per_Nine=18, pacc_Best_Efficiency=19, pacc_Pitching_Rookie_of_the_Year=20 } accolade; } *accolades; } *pitching; struct batter_s { int player_id; int power; int hit_n_run; int bunt; int running; int range; int arm; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } primary_position; enum position_e { pos_None=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_LeftField=6, pos_CenterField=7, pos_RightField=8, pos_Infield=9, pos_Outfield=10 } secondary_position; struct batter_stats_s { int player_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *stats; struct batter_accolade_s { int player_id; int season; enum batting_accolade_e { bacc_None=0, bacc_Batter_of_the_Year=1, bacc_Global_Batter_of_the_Year=2, bacc_World_Batter_of_the_Year=3, bacc_Atlantic_Batter_of_the_Year=4, bacc_North_Batter_of_the_Year=5, bacc_Pacific_Batter_of_the_Year=6, bacc_South_Batter_of_the_Year=7, bacc_Best_Batting_Average=8, bacc_Most_Doubles=9, bacc_Most_Triples=10, bacc_Most_Home_Runs=11, bacc_Most_Runs=12, bacc_Most_Runs_Batted_In=13, bacc_Most_Stolen_Bases=14, bacc_Most_Walks=15, bacc_Best_Slugging_Average=16, bacc_Best_On_Base_Percentage=17, bacc_Best_Strike_Out_Average=18, bacc_Best_Runs_per_Game=19, bacc_Batting_Rookie_of_the_Year=20 } accolade; } *accolades; } *batting; } details; } *player; } *players; struct team_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct team_versus_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; } *versus_stats; struct team_pitching_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } *pitching_stats; struct team_batting_stats_s { int team_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; } *batting_stats; struct team_accolade_s { int team_id; int season; enum team_accolade_e { tacc_None=0, tacc_World_Title=1, tacc_League_Title=2, tacc_Division_Title=3, tacc_Best_Record=4, tacc_All_Star_Champion=5 } accolade; } *accolades; } *team; } *teams; struct division_stats_s { int division_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; } *stats; struct division_accolade_s { int division_id; int season; enum division_accolade_e { dacc_None=0, dacc_World_Title=1, dacc_League_Title=2, dacc_Best_Record=3 } accolade; } *accolades; } *division; } *divisions; struct league_team_s { int league_id; int team_id; struct team_s *team; } *teams; struct league_stats_s { int league_id; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int runs_scored; int runs_allowed; } *stats; struct league_accolade_s { int league_id; int season; enum league_accolade_e { lacc_None=0, lacc_World_Title=1, lacc_Best_Record=2, lacc_All_Star_Champion=3 } accolade; } *accolades; } *league; } *leagues; } *

variable_types: struct fileleagname_s { unsigned char header[52]; struct fileleague_s { unsigned char name[12]; } leagues[2]; struct filedivision_s { unsigned char name[12]; } divisions[-1]; struct fileteam_s { unsigned char name[11]; unsigned char stadium[1]; unsigned char color[1]; unsigned char wins[1]; unsigned char losses[1]; unsigned char team_id[1]; } teams[-1]; } *

variable_types: i int

variable_types: j int

variable_types: k int

user_defined_types: struct org_s { struct org_league_s *leagues; }

user_defined_types: struct fileleagname_s { unsigned char header[52]; struct fileleague_s leagues[2]; struct filedivision_s divisions[-1]; struct fileteam_s teams[-1]; }

user_defined_types: struct league_s { int league_id; char name[-1]; struct league_division_s *divisions; struct league_team_s *teams; struct league_stats_s *stats; struct league_accolade_s *accolades; }

user_defined_types: struct division_s { int division_id; char name[-1]; struct division_team_s *teams; struct division_stats_s *stats; struct division_accolade_s *accolades; }

user_defined_types: struct org_league_s { struct league_s *league; }

user_defined_types: struct league_division_s { int league_id; int division_id; struct division_s *division; }

user_defined_types: struct league_stats_s { int league_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct league_accolade_s { int league_id; int season; enum league_accolade_e accolade; }

user_defined_types: struct division_team_s { int division_id; int team_id; struct team_s *team; }

user_defined_types: struct division_stats_s { int division_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct division_accolade_s { int division_id; int season; enum division_accolade_e accolade; }

user_defined_types: struct team_player_s { int team_id; int season; int player_id; struct player_s *player; }

user_defined_types: struct team_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int home_wins; int home_losses; int road_wins; int road_losses; int division_wins; int division_losses; int league_wins; int league_losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_versus_stats_s { int team_id; int season; enum season_phase_e season_phase; int opponent; int wins; int losses; int runs_scored; int runs_allowed; }

user_defined_types: struct team_pitching_stats_s { int team_id; int season; enum season_phase_e season_phase; int wins; int losses; int games; int saves; struct innings_s innings; int hits; int earned_runs; int home_runs; int walks; int strike_outs; }

user_defined_types: struct team_batting_stats_s { int team_id; int season; enum season_phase_e season_phase; int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int runs_batted_in; int walks; int strike_outs; int steals; int errors; }

user_defined_types: struct team_accolade_s { int team_id; int season; enum team_accolade_e accolade; }

user_defined_types: struct player_s { int player_id; char first_name[-1]; char last_name[-1]; char first_phoenetic[-1]; char last_phoenetic[-1]; enum skin_tone_e skin_tone; enum handedness_e handedness; enum playertype_e player_type; int rookie_season; int longevity; struct player_accolade_s *accolades; union { struct pitcher_s *pitching; struct batter_s *batting; } details; }

user_defined_types: struct player_accolade_s { int player_id; int season; enum accolade_e accolade; }


buildFileLeagName

decompiled_code:
void *buildFileLeagName()
{
char *v0; // rbp
unsigned int v1; // ebx
char *v2; // rdi
char *v3; // rbx
unsigned int i; // ebp
unsigned int v5; // er12
char *v6; // rdi

v0 = byte_12C;
v1 = 0;
sprintf(s, "League%d", 1LL);
sprintf(byte_120, "League%d", 2LL);
do
{
++v1;
v2 = v0;
v0 += 12;
sprintf(v2, "Division%d", v1);
}
while ( v1 != 4 );
v3 = byte_15C;
for ( i = 0; i != 32; int2byte(v6, i) )
{
v5 = i++;
sprintf(v3, "Team%d", i);
int2byte(v3 + 11, v5);
int2byte(v3 + 12, i);
int2byte(v3 + 13, v5);
int2byte(v3 + 14, v5);
v6 = v3 + 15;
v3 += 16;
}
return &league_data_0;
}

canonical_decompiled_code:
void *func0()
{
char *v0; // rbp
unsigned int v1; // ebx
char *v2; // rdi
char *v3; // rbx
unsigned int i; // ebp
unsigned int v5; // er12
char *v6; // rdi

v0 = byte_12C;
v1 = 0;
sprintf(s, "League%d", 1LL);
sprintf(byte_120, "League%d", 2LL);
do
{
++v1;
v2 = v0;
v0 += 12;
sprintf(v2, "Division%d", v1);
}
while ( v1 != 4 );
v3 = byte_15C;
for ( i = 0; i != 32; int2byte(v6, i) )
{
v5 = i++;
sprintf(v3, "Team%d", i);
int2byte(v3 + 11, v5);
int2byte(v3 + 12, i);
int2byte(v3 + 13, v5);
int2byte(v3 + 14, v5);
v6 = v3 + 15;
v3 += 16;
}
return &league_data_0;
}

original_code:
fileleagname_s *buildFileLeagName( void )
{
     static fileleagname_s league_data = { 0 };
     for ( int i = 0; i < 2; ++i )
     {
          sprintf( league_data.leagues[i].name, "League%d", i + 1 );
     }
     for ( int i = 0; i < (2 * 2); ++i )
     {
          sprintf( league_data.divisions[i].name, "Division%d", i + 1 );
     }
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          sprintf( league_data.teams[i].name, "Team%d", i + 1 );
          int2byte( league_data.teams[i].stadium, i );
          int2byte( league_data.teams[i].color, i + 1 );
          int2byte( league_data.teams[i].wins, i );
          int2byte( league_data.teams[i].losses, i );
          int2byte( league_data.teams[i].team_id, i + 1 );
     }
     return &league_data;
}

canonical_original_code:
struct fileleagname_s *buildFileLeagName()
{
     static struct fileleagname_s league_data = { 0 };
     for ( int i = 0; i < 2; ++i )
     {
          sprintf( league_data.leagues[i].name, "League%d", i + 1 );
     }
     for ( int i = 0; i < (2 * 2); ++i )
     {
          sprintf( league_data.divisions[i].name, "Division%d", i + 1 );
     }
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          sprintf( league_data.teams[i].name, "Team%d", i + 1 );
          int2byte( league_data.teams[i].stadium, i );
          int2byte( league_data.teams[i].color, i + 1 );
          int2byte( league_data.teams[i].wins, i );
          int2byte( league_data.teams[i].losses, i );
          int2byte( league_data.teams[i].team_id, i + 1 );
     }
     return &league_data;
}

return_type: struct fileleagname_s { unsigned char header[52]; struct fileleague_s { unsigned char name[12]; } leagues[2]; struct filedivision_s { unsigned char name[12]; } divisions[-1]; struct fileteam_s { unsigned char name[11]; unsigned char stadium[1]; unsigned char color[1]; unsigned char wins[1]; unsigned char losses[1]; unsigned char team_id[1]; } teams[-1]; } *

user_defined_types: struct fileleagname_s { unsigned char header[52]; struct fileleague_s leagues[2]; struct filedivision_s divisions[-1]; struct fileteam_s teams[-1]; }


displayAvg

decompiled_code:
char *__fastcall displayAvg(double a1)
{
sprintf(&buffer_0, "%5.3f", a1);
if ( buffer_0 == 48 )
buffer_0 = 32;
return &buffer_0;
}

canonical_decompiled_code:
char *__fastcall func4(double a1)
{
sprintf(&buffer_0, "%5.3f", a1);
if ( buffer_0 == 48 )
buffer_0 = 32;
return &buffer_0;
}

original_code:
static char *displayAvg( const double avg )
{
     static char buffer[5 + 1];
     sprintf( buffer, "%5.3f", avg );
     if ( buffer[0] == '0' ) buffer[0] = ' ';
     return buffer;
}

canonical_original_code:
static char *displayAvg(double avg)
{
     static char buffer[-1];
     sprintf( buffer, "%5.3f", avg );
     if ( buffer[0] == '0' ) buffer[0] = ' ';
     return buffer;
}

variable_types: avg double

variable_types:
buffer
char [-1]


printPlayer

decompiled_code:
int __fastcall printPlayer(__int64 a1)
{
int result; // eax

result = *(_DWORD *)(a1 + 8);
if ( !result )
return printPitcher(a1);
if ( result == 1 )
result = printHitter(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int result; // eax

result = *(_DWORD *)(a1 + 8);
if ( !result )
return func10(a1);
if ( result == 1 )
result = func8(a1);
return result;
}

original_code:
static void printPlayer( const player_s *player )
{
     if ( player->type == pt_Pitcher ) printPitcher( player );
     else if ( player->type == pt_Hitter ) printHitter( player );
}

canonical_original_code:
static void printPlayer(struct player_s *player)
{
     if ( player->type == pt_Pitcher ) printPitcher( player );
     else if ( player->type == pt_Hitter ) printHitter( player );
}

variable_types: struct player_s { int player_id; int hand; enum playertype_e { pt_Pitcher=0, pt_Hitter=1, pt_None=2 } type; int injury_days; union { struct pitcher_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int speed; int control; int fatigue; int bunt; int longevity; struct pitching_s { int wins; int losses; int games; int games_started; int games_completed; int saves; float innings; int at_bats; int hits; int earned_runs; int home_runs; int walks; int strike_outs; } potential; struct pitching_s simulated; float fielding_avg; } pitcher; struct batter_s { char first_name[-1]; char last_name[-1]; int year; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } primary_pos; enum position_e { pos_Pitcher=0, pos_Catcher=1, pos_FirstBase=2, pos_SecondBase=3, pos_ThirdBase=4, pos_ShortStop=5, pos_Infield=6, pos_LeftField=7, pos_CenterField=8, pos_RightField=9, pos_Outfield=10, pos_Unknown=11, pos_Designate=12 } secondary_pos; int power; int hit_n_run; int bunt; int running; int range; int arm; int longevity; struct hitting_s { int games; int at_bats; int runs; int hits; int doubles; int triples; int home_runs; int rbi; int walks; int strike_outs; int stolen_bases; int errors; } potential; struct hitting_s simulated; struct fielding_s { int put_outs; int assists; int errors; float secondary_avg; } fielding; } batter; } data; } *

user_defined_types: struct player_s { int player_id; int hand; enum playertype_e type; int injury_days; union { struct pitcher_s pitcher; struct batter_s batter; } data; }

user_defined_types: struct pitcher_s { char first_name[-1]; char last_name[-1]; int year; enum position_e primary_pos; enum position_e secondary_pos; int speed; int control; int fatigue; int bunt; int longevity; struct pitching_s potential; struct pitching_s simulated; float fielding_avg; }

user_defined_types: struct batter_s { char first_name[-1]; char last_name[-1]; int year; enum position_e primary_pos; enum position_e secondary_pos; int power; int hit_n_run; int bunt; int running; int range; int arm; int longevity; struct hitting_s potential; struct hitting_s simulated; struct fielding_s fielding; }