calcChecksum

decompiled_code:
__int64 __fastcall calcChecksum(int a1)
{
int v1; // ecx
unsigned int v2; // esi
int v3; // edx

if ( a1 <= 0 )
return 0LL;
v1 = 0;
do
{
v2 = a1 % 0xAu;
v3 = a1;
a1 /= 0xAu;
v1 += v2;
}
while ( v3 > 9 );
return (unsigned int)(3 * v1);
}

canonical_decompiled_code:
__int64 __fastcall func17(int a1)
{
int v1; // ecx
unsigned int v2; // esi
int v3; // edx

if ( a1 <= 0 )
return 0LL;
v1 = 0;
do
{
v2 = a1 % 0xAu;
v3 = a1;
a1 /= 0xAu;
v1 += v2;
}
while ( v3 > 9 );
return (unsigned int)(3 * v1);
}

original_code:
unsigned char calcChecksum( int value )
{
     unsigned char checksum = 0;
     while ( value > 0 )
     {
          checksum += value % 10;
          value /= 10;
     }
     return checksum * 3;
}

canonical_original_code:
unsigned char calcChecksum(int value)
{
     unsigned char checksum = 0;
     while ( value > 0 )
     {
          checksum += value % 10;
          value /= 10;
     }
     return checksum * 3;
}

variable_types: value int

variable_types:
checksum
unsigned char

return_type: unsigned char


findMatchingPlayer

repo: zjentohlauedy/MBA

original_code:
fileplayer_s *findMatchingPlayer( const fileplayer_s *player, fileplayer_s *players )
{
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( memcmp( player->first_name, players[i].first_name, sizeof(player->first_name) ) == 0 &&
               memcmp( player->last_name, players[i].last_name, sizeof(player->last_name) ) == 0 )
          {
               return &players[i];
          }
     }
     return ((void *)0);
}

canonical_original_code:
struct fileplayer_s *findMatchingPlayer(struct fileplayer_s *player, struct fileplayer_s *players)
{
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          if ( memcmp( player->first_name, players[i].first_name, sizeof(player->first_name) ) == 0 &&
               memcmp( player->last_name, players[i].last_name, sizeof(player->last_name) ) == 0 )
          {
               return &players[i];
          }
     }
     return ((void *)0);
}

variable_types:
player
struct fileplayer_s *

variable_types:
players
struct fileplayer_s *

variable_types: i int

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

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


freeSchedule

decompiled_code:
void __fastcall freeSchedule(void *ptr)
{
void **v2; // r8
void *v3; // rdi
__int64 v4; // rbx

v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
v3 = *v2;
if ( *v2 )
{
v4 = 8LL;
do
{
free(v3);
v2 = *(void ***)ptr;
v3 = *(void **)(*(_QWORD *)ptr + v4);
v4 += 8LL;
}
while ( v3 );
}
free(v2);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func25(void *ptr)
{
void **v2; // r8
void *v3; // rdi
__int64 v4; // rbx

v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
v3 = *v2;
if ( *v2 )
{
v4 = 8LL;
do
{
free(v3);
v2 = *(void ***)ptr;
v3 = *(void **)(*(_QWORD *)ptr + v4);
v4 += 8LL;
}
while ( v3 );
}
free(v2);
}
free(ptr);
}

original_code:
void freeSchedule( schedule_s *schedule )
{
     if ( schedule->days != ((void *)0) )
     {
          for ( int i = 0; schedule->days[i].games != ((void *)0); ++i )
          {
               free( schedule->days[i].games );
          }
          free( schedule->days );
     }
     free( schedule );
}

canonical_original_code:
void freeSchedule(struct schedule_s *schedule)
{
     if ( schedule->days != ((void *)0) )
     {
          for ( int i = 0; schedule->days[i].games != ((void *)0); ++i )
          {
               free( schedule->days[i].games );
          }
          free( schedule->days );
     }
     free( schedule );
}

variable_types: struct schedule_s { struct schedule_day_s { struct schedule_game_s { struct schedule_team_s { char name[20]; int score; } road; struct schedule_team_s home; enum boolean_e { bl_False=0, bl_True=1 } played; } *games; } *days; } *

return_type: void

user_defined_types: struct schedule_s { struct schedule_day_s *days; }

user_defined_types: struct schedule_day_s { struct schedule_game_s *games; }

user_defined_types: struct schedule_game_s { struct schedule_team_s road; struct schedule_team_s home; enum boolean_e played; }


clearErrorMessage

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

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

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

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


isAllstarTeam

decompiled_code:
_BOOL8 __fastcall isAllstarTeam(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( !strcmp(a1, a2) )
result = 1LL;
else
result = strcmp(a1 + 20, a2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( !strcmp(a1, a2) )
result = 1LL;
else
result = strcmp(a1 + 20, a2) == 0;
return result;
}

original_code:
static boolean_e isAllstarTeam( struct league *leagues, char *team )
{
     for ( int i = 0; i < 2; ++i )
     {
          if ( strcmp( leagues[i].name, team ) == 0 ) return bl_True;
     }
     return bl_False;
}

canonical_original_code:
static enum boolean_e isAllstarTeam(struct league *leagues, char *team)
{
     for ( int i = 0; i < 2; ++i )
     {
          if ( strcmp( leagues[i].name, team ) == 0 ) return bl_True;
     }
     return bl_False;
}

variable_types:
leagues
struct league { char name[20]; } *

variable_types:
team
char *

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


findTeam

decompiled_code:
__int64 __fastcall findTeam(char *s1, char *s2)
{
unsigned int i; // er12

for ( i = 0; i != 32; ++i )
{
if ( !strcmp(s1, s2) )
return i;
s1 += 28;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1, char *s2)
{
unsigned int i; // er12

for ( i = 0; i != 32; ++i )
{
if ( !strcmp(s1, s2) )
return i;
s1 += 28;
}
return 0xFFFFFFFFLL;
}

original_code:
static int findTeam( struct team *teams, char *team )
{
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( strcmp( teams[i].name, team ) == 0 ) return i;
     }
     return -1;
}

canonical_original_code:
static int findTeam(struct team *teams, char *team)
{
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( strcmp( teams[i].name, team ) == 0 ) return i;
     }
     return -1;
}

variable_types: struct team { char name[20]; int league; int division; } *

return_type: int


getCalculateRecordsError

decompiled_code:
char *getCalculateRecordsError()
{
return error_message;
}

canonical_decompiled_code:
char *func3()
{
return error_message;
}

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

return_type: char *


freeRecords

decompiled_code:
void __fastcall freeRecords(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 24);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 280) );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi
void **v5; // rbx

v2 = *(void **)ptr;
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 1);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 2);
if ( v4 )
free(v4);
v5 = (void **)((char *)ptr + 24);
do
{
if ( *v5 )
free(*v5);
++v5;
}
while ( v5 != (void **)((char *)ptr + 280) );
free(ptr);
}

original_code:
void freeRecords( records_s *records )
{
     if ( records->leagues != ((void *)0) ) free( records->leagues );
     if ( records->divisions != ((void *)0) ) free( records->divisions );
     if ( records->teams != ((void *)0) ) free( records->teams );
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( records->versus[i] != ((void *)0) ) free( records->versus[i] );
     }
     free( records );
}

canonical_original_code:
void freeRecords(struct records_s *records)
{
     if ( records->leagues != ((void *)0) ) free( records->leagues );
     if ( records->divisions != ((void *)0) ) free( records->divisions );
     if ( records->teams != ((void *)0) ) free( records->teams );
     for ( int i = 0; i < ((8 * 2) * 2); ++i )
     {
          if ( records->versus[i] != ((void *)0) ) free( records->versus[i] );
     }
     free( records );
}

variable_types: struct records_s { 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; } *leagues; 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; } *divisions; 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; } *teams; 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[-1]; } *

user_defined_types: struct records_s { struct league_stats_s *leagues; struct division_stats_s *divisions; struct team_stats_s *teams; struct team_versus_stats_s *versus[-1]; }

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


decompiled_code:
void __fastcall free_division_teams(void *ptr)
{
_DWORD *v1; // rbx
int v2; // eax

if ( *(int *)ptr >= 0 )
{
v1 = (char *)ptr + 16;
do
{
if ( *((_QWORD *)v1 - 1) )
free_team();
v2 = *v1;
v1 += 4;
}
while ( v2 >= 0 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func13(void *ptr)
{
_DWORD *v1; // rbx
int v2; // eax

if ( *(int *)ptr >= 0 )
{
v1 = (char *)ptr + 16;
do
{
if ( *((_QWORD *)v1 - 1) )
free_team();
v2 = *v1;
v1 += 4;
}
while ( v2 >= 0 );
}
free(ptr);
}

original_code:
void free_division_teams( division_team_s *division_teams )
{
     for ( int i = 0; division_teams[i].division_id >= 0; ++i )
     {
          if ( division_teams[i].team != ((void *)0) ) free_team( division_teams[i].team );
     }
     free( division_teams );
}

canonical_original_code:
void free_division_teams(struct division_team_s *division_teams)
{
     for ( int i = 0; division_teams[i].division_id >= 0; ++i )
     {
          if ( division_teams[i].team != ((void *)0) ) free_team( division_teams[i].team );
     }
     free( division_teams );
}

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

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

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


decompiled_code:
void __fastcall free_division(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
free_division_teams(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 6);
if ( v4 )
free(v4);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func14(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

v2 = (void *)*((_QWORD *)ptr + 4);
if ( v2 )
func13(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 6);
if ( v4 )
free(v4);
free(ptr);
}

original_code:
void free_division( division_s *division )
{
     if ( division->teams != ((void *)0) ) free_division_teams( division->teams );
     if ( division->stats != ((void *)0) ) free( division->stats );
     if ( division->accolades != ((void *)0) ) free( division->accolades );
     free( division );
}

canonical_original_code:
void free_division(struct division_s *division)
{
     if ( division->teams != ((void *)0) ) free_division_teams( division->teams );
     if ( division->stats != ((void *)0) ) free( division->stats );
     if ( division->accolades != ((void *)0) ) free( division->accolades );
     free( division );
}

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

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


convertLeagueStats

decompiled_code:
__int64 __fastcall convertLeagueStats(__int64 a1)
{
int v1; // er8
__int64 result; // rax
__int128 v3; // [rsp+0h] [rbp-48h] BYREF
__int64 v4[5]; // [rsp+10h] [rbp-38h] BYREF
int v5; // [rsp+38h] [rbp-10h]

v3 = 0LL;
v4[0] = -1LL;
v4[1] = 0xFFFFFFFF00000000LL;
v4[2] = -1LL;
v4[3] = -1LL;
v4[4] = -1LL;
v5 = -1;
v1 = add_to_data_list(&v3, a1, 44LL, 5LL);
result = 0LL;
if ( v1 >= 0 )
{
add_to_data_list(&v3, v4, 44LL, 5LL);
result = *((_QWORD *)&v3 + 1);
}
return result;
}

original_code:
static league_stats_s *convertLeagueStats( league_stats_s *league_stats )
{
     data_list_s list = { 0 };
     league_stats_s sentinel = { -1, -1, sp_None, -1, -1, -1, -1, -1, -1, -1, -1 };
     if ( add_to_data_list( &list, league_stats, sizeof(league_stats_s), 5 ) < 0 ) return ((void *)0);
          add_to_data_list( &list, &sentinel, sizeof(league_stats_s), 5 );
     return list.data;
}

canonical_original_code:
static struct league_stats_s *convertLeagueStats(struct league_stats_s *league_stats)
{
     struct data_list_s list = { 0 };
     struct league_stats_s sentinel = { -1, -1, sp_None, -1, -1, -1, -1, -1, -1, -1, -1 };
     if ( add_to_data_list( &list, league_stats, sizeof(league_stats_s), 5 ) < 0 ) return ((void *)0);
          add_to_data_list( &list, &sentinel, sizeof(league_stats_s), 5 );
     return list.data;
}

variable_types: struct data_list_s { int __max; int count; void *data; }

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

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


addLeagueToList

decompiled_code:
_BOOL8 __fastcall addLeagueToList(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return (int)add_to_data_list(a1, &v3, 8LL, 5LL) >= 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return (int)add_to_data_list(a1, &v3, 8LL, 5LL) >= 0;
}

original_code:
static boolean_e addLeagueToList( data_list_s *list, league_s *league )
{
     org_league_s org_league = { 0 };
     org_league.league = league;
     if ( add_to_data_list( list, &org_league, sizeof(org_league_s), 5 ) < 0 ) return bl_False;
     return bl_True;
}

canonical_original_code:
static enum boolean_e addLeagueToList(struct data_list_s *list, struct league_s *league)
{
     struct org_league_s org_league = { 0 };
     org_league.league = league;
     if ( add_to_data_list( list, &org_league, sizeof(org_league_s), 5 ) < 0 ) return bl_False;
     return bl_True;
}

variable_types: struct data_list_s { int __max; int count; void *data; } *

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

user_defined_types: struct org_league_s { struct league_s *league; }

user_defined_types: enum boolean_e { bl_False=0, bl_True=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 league_division_s { int league_id; int division_id; struct division_s *division; }

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


createLeague

decompiled_code:
char *__fastcall createLeague(int a1, const char *a2)
{
char *v2; // rax
char *v3; // r12

v2 = (char *)calloc(0x40uLL, 1uLL);
v3 = v2;
if ( v2 )
{
*(_DWORD *)v2 = a1;
strcpy(v2 + 4, a2);
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func2(int a1, const char *a2)
{
char *v2; // rax
char *v3; // r12

v2 = (char *)calloc(0x40uLL, 1uLL);
v3 = v2;
if ( v2 )
{
*(_DWORD *)v2 = a1;
strcpy(v2 + 4, a2);
}
return v3;
}

original_code:
static league_s *createLeague( const int league_id, const char *name )
{
     league_s *league = ((void *)0);
     if ( (league = malloc( sizeof(league_s) )) == ((void *)0) ) return ((void *)0);
     memset( league, '\0', sizeof(league_s) );
             league->league_id = league_id;
     strcpy( league->name, name );
     return league;
}

canonical_original_code:
static struct league_s *createLeague(int league_id, char *name)
{
     struct league_s *league = ((void *)0);
     if ( (league = malloc( sizeof(league_s) )) == ((void *)0) ) return ((void *)0);
     memset( league, '\0', sizeof(league_s) );
             league->league_id = league_id;
     strcpy( league->name, name );
     return league;
}

variable_types:
name
char *

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 team_player_s { int team_id; int season; int player_id; struct player_s *player; }

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


convertLeagues

decompiled_code:
__int64 __fastcall convertLeagues(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er13
char *v3; // rax
char *v4; // rbp
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // rax
__int64 v9; // rax
__int64 v10; // [rsp+0h] [rbp-50h] BYREF
__int128 v11; // [rsp+8h] [rbp-48h] BYREF
__int128 v12[3]; // [rsp+18h] [rbp-38h] BYREF

v1 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12[0] = 0LL;
while ( 1 )
{
v2 = v1 + 1;
v3 = createLeague((int)v1 + 1, (const char *)(*(_QWORD *)a1 + 12 * v1 + 52));
*((_QWORD *)v12 + v1) = v3;
v4 = v3;
if ( !v3 )
break;
if ( *(_DWORD *)(a1 + 36) == 3 )
{
v9 = convertLeagueTeams(a1, v2, (unsigned int)v1);
*((_QWORD *)v4 + 5) = v9;
if ( !v9 )
break;
}
else
{
v5 = convertDivisions(a1, v2, (unsigned int)v1);
*((_QWORD *)v4 + 4) = v5;
if ( !v5 )
break;
}
v6 = *((_QWORD *)v12 + v1);
v7 = convertLeagueStats(**(_QWORD **)(a1 + 24) + 44 * v1);
*(_QWORD *)(v6 + 48) = v7;
if ( !v7 || !addLeagueToList((__int64)&v11, *((_QWORD *)v12 + v1)) )
break;
if ( v1 == 1 )
{
add_to_data_list(&v11, &v10, 8LL, 5LL);
return *((_QWORD *)&v11 + 1);
}
v1 = 1LL;
}
freeLeagues_constprop_0(v12);
return 0LL;
}

original_code:
org_league_s *convertLeagues( const org_data_s *org_data )
{
     data_list_s list = { 0 };
     org_league_s sentinel = { 0 };
     league_s *leagues[2] = { 0 };
     for ( int i = 0; i < 2; ++i )
     {
          int league_id = i + 1;
          if ( (leagues[i] = createLeague( league_id, org_data->league_data->leagues[i].name )) == ((void *)0) )
          {
               freeLeagues( leagues, 2 );
               return ((void *)0);
          }
          if ( org_data->season_phase == sp_Allstar )
          {
               if ( (leagues[i]->teams = convertLeagueTeams( org_data, league_id, i )) == ((void *)0) )
               {
                    freeLeagues( leagues, 2 );
                    return ((void *)0);
               }
          }
          else
          {
               if ( (leagues[i]->divisions = convertDivisions( org_data, league_id, i )) == ((void *)0) )
               {
                    freeLeagues( leagues, 2 );
                    return ((void *)0);
               }
          }
          if ( (leagues[i]->stats = convertLeagueStats( &(org_data->records->leagues[i]) )) == ((void *)0) )
          {
               freeLeagues( leagues, 2 );
               return ((void *)0);
          }
          if ( addLeagueToList( &list, leagues[i] ) != bl_True )
          {
               freeLeagues( leagues, 2 );
               return ((void *)0);
          }
     }
     add_to_data_list( &list, &sentinel, sizeof(org_league_s), 5 );
     return list.data;
}

canonical_original_code:
struct org_league_s *convertLeagues(struct org_data_s *org_data)
{
     struct data_list_s list = { 0 };
     struct org_league_s sentinel = { 0 };
     struct league_s *leagues[2] = { 0 };
     for ( int i = 0; i < 2; ++i )
     {
          int league_id = i + 1;
          if ( (leagues[i] = createLeague( league_id, org_data->league_data->leagues[i].name )) == ((void *)0) )
          {
               freeLeagues( leagues, 2 );
               return ((void *)0);
          }
          if ( org_data->season_phase == sp_Allstar )
          {
               if ( (leagues[i]->teams = convertLeagueTeams( org_data, league_id, i )) == ((void *)0) )
               {
                    freeLeagues( leagues, 2 );
                    return ((void *)0);
               }
          }
          else
          {
               if ( (leagues[i]->divisions = convertDivisions( org_data, league_id, i )) == ((void *)0) )
               {
                    freeLeagues( leagues, 2 );
                    return ((void *)0);
               }
          }
          if ( (leagues[i]->stats = convertLeagueStats( &(org_data->records->leagues[i]) )) == ((void *)0) )
          {
               freeLeagues( leagues, 2 );
               return ((void *)0);
          }
          if ( addLeagueToList( &list, leagues[i] ) != bl_True )
          {
               freeLeagues( leagues, 2 );
               return ((void *)0);
          }
     }
     add_to_data_list( &list, &sentinel, sizeof(org_league_s), 5 );
     return list.data;
}

variable_types: struct org_data_s { 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]; } *league_data; 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]; } *parks_data; 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; } *players_data; struct records_s { struct league_stats_s *leagues; struct division_stats_s *divisions; struct team_stats_s *teams; struct team_versus_stats_s *versus[-1]; } *records; int season; enum season_phase_e { sp_None=0, sp_Regular=1, sp_Playoff=2, sp_Allstar=3 } season_phase; } *

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; } *[2]

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

user_defined_types: struct data_list_s { int __max; int count; void *data; }

user_defined_types: struct org_league_s { struct league_s *league; }

user_defined_types: struct org_data_s { struct fileleagname_s *league_data; struct fileparks_s *parks_data; struct fileplayer_s *players_data; struct records_s *records; int season; enum season_phase_e season_phase; }

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 fileparks_s { unsigned char filler[52]; struct park_name_s park_names[32]; struct park_details_s park_details[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 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: 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 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]; }

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

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


buildFilePitcherStats

decompiled_code:
__int64 __fastcall buildFilePitcherStats(__int64 a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // ebp
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax

v1 = rand();
int2byte(a1, (unsigned int)(v1 % 250));
v2 = rand();
int2byte(a1 + 1, (unsigned int)(v2 % 250));
v3 = rand();
int2byte(a1 + 2, (unsigned int)(v3 % 250));
v4 = rand();
int2byte(a1 + 3, (unsigned int)(v4 % 250));
v5 = rand();
v6 = rand();
int2word(a1 + 4, (unsigned int)(v5 % 5000 + v6 % 3));
v7 = rand();
int2word(a1 + 6, (unsigned int)(v7 % 50000));
v8 = rand();
int2word(a1 + 8, (unsigned int)(v8 % 50000));
v9 = rand();
int2byte(a1 + 10, (unsigned int)(v9 % 250));
v10 = rand();
int2byte(a1 + 11, (unsigned int)(v10 % 250));
v11 = rand();
return int2word(a1 + 12, (unsigned int)(v11 % 50000));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // ebp
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax

v1 = rand();
int2byte(a1, (unsigned int)(v1 % 250));
v2 = rand();
int2byte(a1 + 1, (unsigned int)(v2 % 250));
v3 = rand();
int2byte(a1 + 2, (unsigned int)(v3 % 250));
v4 = rand();
int2byte(a1 + 3, (unsigned int)(v4 % 250));
v5 = rand();
v6 = rand();
int2word(a1 + 4, (unsigned int)(v5 % 5000 + v6 % 3));
v7 = rand();
int2word(a1 + 6, (unsigned int)(v7 % 50000));
v8 = rand();
int2word(a1 + 8, (unsigned int)(v8 % 50000));
v9 = rand();
int2byte(a1 + 10, (unsigned int)(v9 % 250));
v10 = rand();
int2byte(a1 + 11, (unsigned int)(v10 % 250));
v11 = rand();
return int2word(a1 + 12, (unsigned int)(v11 % 50000));
}

original_code:
static void buildFilePitcherStats( acc_pch_stats_s *stats )
{
     int2byte( stats->acc_wins, rand() % 250 );
     int2byte( stats->acc_losses, rand() % 250 );
     int2byte( stats->acc_starts, rand() % 250 );
     int2byte( stats->acc_saves, rand() % 250 );
     int2word( stats->acc_innings, (rand() % 5000) + (rand() % 3) );
     int2word( stats->acc_hits, rand() % 50000 );
     int2word( stats->acc_er, rand() % 50000 );
     int2byte( stats->acc_hr, rand() % 250 );
     int2byte( stats->acc_bb, rand() % 250 );
     int2word( stats->acc_so, rand() % 50000 );
}

canonical_original_code:
static void buildFilePitcherStats(struct acc_pch_stats_s *stats)
{
     int2byte( stats->acc_wins, rand() % 250 );
     int2byte( stats->acc_losses, rand() % 250 );
     int2byte( stats->acc_starts, rand() % 250 );
     int2byte( stats->acc_saves, rand() % 250 );
     int2word( stats->acc_innings, (rand() % 5000) + (rand() % 3) );
     int2word( stats->acc_hits, rand() % 50000 );
     int2word( stats->acc_er, rand() % 50000 );
     int2byte( stats->acc_hr, rand() % 250 );
     int2byte( stats->acc_bb, rand() % 250 );
     int2word( stats->acc_so, rand() % 50000 );
}

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


buildFileBatterStats

decompiled_code:
__int64 __fastcall buildFileBatterStats(__int64 a1, __int64 a2)
{
int v4; // er12
int v5; // ebp
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // eax
__int64 v16; // rdi
__int64 v17; // rdi
__int64 v18; // rsi

v4 = rand() % 500;
v5 = rand() % 500;
v6 = rand();
int2word(a1, (unsigned int)(v6 % 50000));
v7 = rand();
int2word(a1 + 2, (unsigned int)(v7 % 50000));
v8 = rand();
int2byte(a1 + 4, (unsigned int)(v8 % 250));
v9 = rand();
int2byte(a1 + 5, (unsigned int)(v9 % 250));
v10 = rand();
int2byte(a1 + 6, (unsigned int)(v10 % 250));
v11 = rand();
int2byte(a1 + 7, (unsigned int)(v11 % 250));
v12 = rand();
int2byte(a1 + 9, (unsigned int)(v12 % 250));
v13 = rand();
int2byte(a1 + 10, (unsigned int)(v13 % 250));
v14 = rand();
int2byte(a1 + 12, (unsigned int)(v14 % 250));
v15 = rand();
int2byte(a1 + 13, (unsigned int)(v15 % 250));
v16 = a1 + 11;
if ( v4 > 250 )
{
int2byte(v16, 250LL);
int2byte(a2 + 11, (unsigned int)(v4 - 250));
}
else
{
int2byte(v16, (unsigned int)v4);
}
v17 = a1 + 8;
v18 = (unsigned int)v5;
if ( v5 > 250 )
{
int2byte(v17, 250LL);
v18 = (unsigned int)(v5 - 250);
v17 = a2 + 8;
}
return int2byte(v17, v18);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v4; // er12
int v5; // ebp
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v11; // eax
int v12; // eax
int v13; // eax
int v14; // eax
int v15; // eax
__int64 v16; // rdi
__int64 v17; // rdi
__int64 v18; // rsi

v4 = rand() % 500;
v5 = rand() % 500;
v6 = rand();
int2word(a1, (unsigned int)(v6 % 50000));
v7 = rand();
int2word(a1 + 2, (unsigned int)(v7 % 50000));
v8 = rand();
int2byte(a1 + 4, (unsigned int)(v8 % 250));
v9 = rand();
int2byte(a1 + 5, (unsigned int)(v9 % 250));
v10 = rand();
int2byte(a1 + 6, (unsigned int)(v10 % 250));
v11 = rand();
int2byte(a1 + 7, (unsigned int)(v11 % 250));
v12 = rand();
int2byte(a1 + 9, (unsigned int)(v12 % 250));
v13 = rand();
int2byte(a1 + 10, (unsigned int)(v13 % 250));
v14 = rand();
int2byte(a1 + 12, (unsigned int)(v14 % 250));
v15 = rand();
int2byte(a1 + 13, (unsigned int)(v15 % 250));
v16 = a1 + 11;
if ( v4 > 250 )
{
int2byte(v16, 250LL);
int2byte(a2 + 11, (unsigned int)(v4 - 250));
}
else
{
int2byte(v16, (unsigned int)v4);
}
v17 = a1 + 8;
v18 = (unsigned int)v5;
if ( v5 > 250 )
{
int2byte(v17, 250LL);
v18 = (unsigned int)(v5 - 250);
v17 = a2 + 8;
}
return int2byte(v17, v18);
}

original_code:
static void buildFileBatterStats( acc_bat_stats_s *stats, acc_bat_stats_s *overflow )
{
     int rbi = rand() % 500;
     int so = rand() % 500;
     int2word( stats->acc_ab, rand() % 50000 );
     int2word( stats->acc_hits, rand() % 50000 );
     int2byte( stats->acc_2b, rand() % 250 );
     int2byte( stats->acc_3b, rand() % 250 );
     int2byte( stats->acc_hr, rand() % 250 );
     int2byte( stats->acc_bb, rand() % 250 );
     int2byte( stats->acc_games, rand() % 250 );
     int2byte( stats->acc_runs, rand() % 250 );
     int2byte( stats->acc_sb, rand() % 250 );
     int2byte( stats->acc_err, rand() % 250 );
     if ( rbi <= 250 ) { int2byte( stats->acc_rbi, rbi ); }
     else { int2byte( stats->acc_rbi, 250 ); int2byte( overflow->acc_rbi, rbi - 250 ); }
     if ( so <= 250 ) { int2byte( stats->acc_so, so ); }
     else { int2byte( stats->acc_so, 250 ); int2byte( overflow->acc_so, so - 250 ); }
}

canonical_original_code:
static void buildFileBatterStats(struct acc_bat_stats_s *stats, struct acc_bat_stats_s *overflow)
{
     int rbi = rand() % 500;
     int so = rand() % 500;
     int2word( stats->acc_ab, rand() % 50000 );
     int2word( stats->acc_hits, rand() % 50000 );
     int2byte( stats->acc_2b, rand() % 250 );
     int2byte( stats->acc_3b, rand() % 250 );
     int2byte( stats->acc_hr, rand() % 250 );
     int2byte( stats->acc_bb, rand() % 250 );
     int2byte( stats->acc_games, rand() % 250 );
     int2byte( stats->acc_runs, rand() % 250 );
     int2byte( stats->acc_sb, rand() % 250 );
     int2byte( stats->acc_err, rand() % 250 );
     if ( rbi <= 250 ) { int2byte( stats->acc_rbi, rbi ); }
     else { int2byte( stats->acc_rbi, 250 ); int2byte( overflow->acc_rbi, rbi - 250 ); }
     if ( so <= 250 ) { int2byte( stats->acc_so, so ); }
     else { int2byte( stats->acc_so, 250 ); int2byte( overflow->acc_so, so - 250 ); }
}

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

variable_types:
overflow
struct acc_bat_stats_s *

variable_types: rbi int

variable_types: so int


buildFilePlayersWithoutIds

original_code:
fileplayer_s *buildFilePlayersWithoutIds( void )
{
     static fileplayer_s players_data[(((25 * 8) * 2) * 2)] = { 0 };
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          memset( &players_data[i], '\0', sizeof(fileplayer_s) );
          unsigned char pos = pickPosition();
          unsigned char color = ((rand() % 100)) > 49 ? fc_Light : fc_Dark;
          unsigned char longevity = (rand() % 10) + 1;
          unsigned char position;
          int year = (2000 - 1845) + (i / 100);
          acc_stats_s *acc_stats = &(players_data[i].acc_stats);
          if ( pos == fpos_Pitcher )
          {
               filepitching_s *pitching = &(players_data[i].filestats.filepitching);
               unsigned char hand = ((rand() % 100)) > 49 ? fh_Right : fh_Left;
               unsigned char speed = (rand() % 10) + 1;
               unsigned char control = (rand() % 10) + 1;
               unsigned char fatigue = (rand() % 10) + 1;
               position = (pos << 4) + hand;
               pitching->color[0] = color;
               pitching->ratings[0] = (speed << 4) + control;
               pitching->ratings[1] = (fatigue << 4) + longevity;
               buildFilePitcherStats( &(acc_stats->simulated.pitching) );
          }
          else
          {
               filebatting_s *batting = &(players_data[i].filestats.filebatting);
               unsigned char hand = ((rand() % 100)) < 50 ? fh_Left : (rand() % 100) > 94 ? fh_Switch : fh_Right;
               unsigned char pos2 = pickPosition();
               unsigned char power = (rand() % 10) + 1;
               unsigned char hit_n_run = (rand() % 10) + 1;
               unsigned char bunt = (rand() % 10) + 1;
               unsigned char running = (rand() % 10) + 1;
               unsigned char range = (rand() % 10) + 1;
               unsigned char arm = (rand() % 10) + 1;
               position = (pos << 4) + pos2;
               batting->color[0] = color;
               batting->ratings[0] = (hand << 4) + arm;
               batting->ratings[1] = (running << 4) + range;
               batting->ratings[2] = (power << 4) + longevity;
               batting->ratings[3] = (bunt << 4) + hit_n_run;
               buildFileBatterStats( &(acc_stats->simulated.batting), &(acc_stats->action.batting) );
          }
          sprintf( players_data[i].first_name, "Fst%d", i + 1 );
          sprintf( players_data[i].last_name, "Last%d", i + 1 );
          sprintf( players_data[i].first_phoen, "FIR3ST%d", i + 1 );
          sprintf( players_data[i].last_phoen, "LAH4ST%d", i + 1 );
                   players_data[i].year[0] = year;
                   players_data[i].position[0] = position;
     }
     return players_data;
}

canonical_original_code:
struct fileplayer_s *buildFilePlayersWithoutIds()
{
     static struct fileplayer_s players_data[-1] = { 0 };
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          memset( &players_data[i], '\0', sizeof(fileplayer_s) );
          unsigned char pos = pickPosition();
          unsigned char color = ((rand() % 100)) > 49 ? fc_Light : fc_Dark;
          unsigned char longevity = (rand() % 10) + 1;
          unsigned char position;
          int year = (2000 - 1845) + (i / 100);
          struct acc_stats_s *acc_stats = &(players_data[i].acc_stats);
          if ( pos == fpos_Pitcher )
          {
               struct filepitching_s *pitching = &(players_data[i].filestats.filepitching);
               unsigned char hand = ((rand() % 100)) > 49 ? fh_Right : fh_Left;
               unsigned char speed = (rand() % 10) + 1;
               unsigned char control = (rand() % 10) + 1;
               unsigned char fatigue = (rand() % 10) + 1;
               position = (pos << 4) + hand;
               pitching->color[0] = color;
               pitching->ratings[0] = (speed << 4) + control;
               pitching->ratings[1] = (fatigue << 4) + longevity;
               buildFilePitcherStats( &(acc_stats->simulated.pitching) );
          }
          else
          {
               struct filebatting_s *batting = &(players_data[i].filestats.filebatting);
               unsigned char hand = ((rand() % 100)) < 50 ? fh_Left : (rand() % 100) > 94 ? fh_Switch : fh_Right;
               unsigned char pos2 = pickPosition();
               unsigned char power = (rand() % 10) + 1;
               unsigned char hit_n_run = (rand() % 10) + 1;
               unsigned char bunt = (rand() % 10) + 1;
               unsigned char running = (rand() % 10) + 1;
               unsigned char range = (rand() % 10) + 1;
               unsigned char arm = (rand() % 10) + 1;
               position = (pos << 4) + pos2;
               batting->color[0] = color;
               batting->ratings[0] = (hand << 4) + arm;
               batting->ratings[1] = (running << 4) + range;
               batting->ratings[2] = (power << 4) + longevity;
               batting->ratings[3] = (bunt << 4) + hit_n_run;
               buildFileBatterStats( &(acc_stats->simulated.batting), &(acc_stats->action.batting) );
          }
          sprintf( players_data[i].first_name, "Fst%d", i + 1 );
          sprintf( players_data[i].last_name, "Last%d", i + 1 );
          sprintf( players_data[i].first_phoen, "FIR3ST%d", i + 1 );
          sprintf( players_data[i].last_phoen, "LAH4ST%d", i + 1 );
                   players_data[i].year[0] = year;
                   players_data[i].position[0] = position;
     }
     return players_data;
}

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; } [-1]

variable_types: i int

variable_types:
pos
unsigned char

variable_types:
color
unsigned char

variable_types:
longevity
unsigned char

variable_types:
position
unsigned char

variable_types: year int

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

variable_types:
hand
unsigned char

variable_types:
speed
unsigned char

variable_types:
control
unsigned char

variable_types:
fatigue
unsigned char

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

variable_types:
power
unsigned char

variable_types:
bunt
unsigned char

variable_types:
running
unsigned char

variable_types:
range
unsigned char

variable_types:
arm
unsigned char


buildFilePlayers

decompiled_code:
char *buildFilePlayers()
{
char *v0; // r13
char *v1; // rbx
__int64 v2; // rbp
unsigned __int8 v3; // al
char *v4; // rdi

v0 = buildFilePlayersWithoutIds();
v1 = v0 + 84;
do
{
v2 = (unsigned int)(rand() % 50000 + 1);
int2word(v1, v2);
v3 = calcChecksum((unsigned int)v2);
v4 = v1 + 2;
v1 += 112;
int2byte(v4, v3);
}
while ( v1 != &byte_15E54[(_QWORD)v0] );
return v0;
}

canonical_decompiled_code:
char *func4()
{
char *v0; // r13
char *v1; // rbx
__int64 v2; // rbp
unsigned __int8 v3; // al
char *v4; // rdi

v0 = func3();
v1 = v0 + 84;
do
{
v2 = (unsigned int)(rand() % 50000 + 1);
int2word(v1, v2);
v3 = calcChecksum((unsigned int)v2);
v4 = v1 + 2;
v1 += 112;
int2byte(v4, v3);
}
while ( v1 != &byte_15E54[(_QWORD)v0] );
return v0;
}

original_code:
fileplayer_s *buildFilePlayers( void )
{
     fileplayer_s *players_data = buildFilePlayersWithoutIds();
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          int player_id = (rand() % 50000) + 1;
          acc_player_id_s *player_id_data = &(players_data[i].acc_stats.action.id_info);
          int2word( player_id_data->player_id, player_id );
          int2byte( player_id_data->checksum, calcChecksum( player_id ) );
     }
     return players_data;
}

canonical_original_code:
struct fileplayer_s *buildFilePlayers()
{
     struct fileplayer_s *players_data = buildFilePlayersWithoutIds();
     for ( int i = 0; i < (((25 * 8) * 2) * 2); ++i )
     {
          int player_id = (rand() % 50000) + 1;
          struct acc_player_id_s *player_id_data = &(players_data[i].acc_stats.action.id_info);
          int2word( player_id_data->player_id, player_id );
          int2byte( player_id_data->checksum, calcChecksum( player_id ) );
     }
     return players_data;
}

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

variable_types: struct acc_player_id_s { unsigned char player_id[2]; unsigned char checksum[1]; unsigned char filler[11]; } *