#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA678_F31E_F31J_X31J_P31J_SU1E_AU1E_AU2E_AU3E
int16_t F7051_LoadGame(REGISTER int16_t P3711_i_GameIndex)
{
#ifdef MEDIA773_SU1E_AU1E
        unsigned int16_t L3936_i_;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        int16_t L3936_i_;
#endif
        REGISTER GAME* L3924_ps_;
        unsigned int16_t L3937_ui_;
#ifdef MEDIA699_X31J_AU2E_AU3E
        int16_t L6044_;
#endif
        int16_t L5783_;
        GAME L3925_s_Game;
#ifdef MEDIA773_SU1E_AU1E
        int16_t L5786_;
        int16_t L5787_;
#endif
        CSB_SAVE_HEADER* L3926_ps_;
        DM_SAVE_HEADER L3927_s_;
        unsigned int16_t* L3928_pui_;
        unsigned int16_t* L3929_pui_;
#ifdef MEDIA692_X31J
        char L6046_ac_Unreferenced[8];
#endif
#ifdef MEDIA773_SU1E_AU1E
        char* L5785_pc_;
        char* L5784_pc_;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        int16_t L3930_i_FileID;
        PROGRAM_STATE L3931_s_;
        unsigned int16_t L3932_ui_;
        char L3933_c_;
        long L3934_l_;
        char* L6048_pc_;
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        char* L3935_pc_TempBuffer;
#endif
#ifdef MEDIA762_AU1E
        char* L6048_pc_;
        long L3934_l_;
#endif


#ifdef MEDIA762_AU1E
                G3807_ = 1;
                L3935_pc_TempBuffer = 0;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        L3931_s_.Previous = G7128_LastProgramState;
        L3931_s_.Ordinal = ++G7129_ProgramStateOrdinal;
        G7128_LastProgramState = &L3931_s_;
        L3931_s_.ReturnValue = setjmp(L3931_s_.State);
        L3937_ui_ = L3931_s_.ReturnValue;
        if (L3937_ui_) {
                L3924_ps_ = &L3925_s_Game;
                L3931_s_.ReturnValue = 0;
                if ((L3937_ui_ >= 23000) && (L3937_ui_ <= 29999)) {
                        L3936_i_ = -20;
                } else {
                        if (L3933_c_) {
                                F7071_();
                                L3933_c_ = C0_FALSE;
                        }
                        if (L3937_ui_ == 0x1810) {
                                L3936_i_ = -2;
                        } else {
                                L3936_i_ = -1;
                        }
                }
        } else {
                L3933_c_ = C0_FALSE;
#endif
                L3924_ps_ = &L3925_s_Game;
                F0008_MAIN_ClearBytes(M772_CAST_PC(L3924_ps_), (long)sizeof(GAME));
                L3926_ps_ = (CSB_SAVE_HEADER*)&L3924_ps_->SaveHeader;
#ifdef MEDIA773_SU1E_AU1E
                L5783_ = 1;
        do {
                if (P3711_i_GameIndex) {
                        F1992_RequestUtilityDiskInDrive();
                        L5785_pc_ = G3799_pc_ChaosStrikesBackSavedGameFileName;
#ifdef MEDIA772_SU1E
                        if ((G3805_FileHandle = Fopen(G3801_, C0_READ_ONLY)) < 0) {
                                F7072_GetDialogChoiceOrdinal(G3792_CAN_T_FIND_NEW_ADVENTURE, C08_COLOR_RED, G7060_OK, &G2263_s_Input_Dialog1Choice);
#endif
#ifdef MEDIA762_AU1E
                        G3805_FileHandle = F0770_FILE_Open(G3801_);
                        if (G3805_FileHandle == NULL) {
                                F7074_DrawDialogErrorMessage(G3792_CAN_T_FIND_NEW_ADVENTURE, C08_COLOR_RED);
#endif
                                return -1;
                        }
                        L3936_i_ = 1;
                } else {
                        if (F1995_(L5783_ | MASK0x8000_UNKNOWN) == 0) {
                                L3936_i_ = (G3807_) ? -99 : -1;
                                goto loc_1D9A;
                        }
                        L3936_i_ = 1;
                        L5786_ = L5787_ = 1;
#ifdef MEDIA772_SU1E
                        if ((G3805_FileHandle = Fopen(L5785_pc_ = G3797_pc_DungeonMasterSavedGameFileName, C0_READ_ONLY)) < 0) {
                                if ((G3805_FileHandle = Fopen(L5785_pc_ = G3798_pc_DungeonMasterBackupSavedGameFileName, C0_READ_ONLY)) < 0) {
#endif
#ifdef MEDIA762_AU1E
                        if ((G3805_FileHandle = F0770_FILE_Open(L5785_pc_ = G3797_pc_DungeonMasterSavedGameFileName)) == NULL) {
                                if ((G3805_FileHandle = F0770_FILE_Open(L5785_pc_ = G3798_pc_DungeonMasterBackupSavedGameFileName)) == NULL) {
#endif
                                        L5786_ = 0;
                                }
                        }
#ifdef MEDIA772_SU1E
                        Fclose(G3805_FileHandle);
                        if ((G3805_FileHandle = Fopen(L5784_pc_ = G3799_pc_ChaosStrikesBackSavedGameFileName, C0_READ_ONLY)) < 0) {
                                if ((G3805_FileHandle = Fopen(L5784_pc_ = G3800_pc_ChaosStrikesBackBackupSavedGameFileName, C0_READ_ONLY)) < 0) {
#endif
#ifdef MEDIA762_AU1E
                        F0771_FILE_Close(G3805_FileHandle);
                        if ((G3805_FileHandle = F0770_FILE_Open(L5784_pc_ = G3799_pc_ChaosStrikesBackSavedGameFileName)) == NULL) {
                                if ((G3805_FileHandle = F0770_FILE_Open(L5784_pc_ = G3800_pc_ChaosStrikesBackBackupSavedGameFileName)) == NULL) {
#endif
                                        L5787_ = 0;
                                }
                        }
#ifdef MEDIA772_SU1E
                        Fclose(G3805_FileHandle);
#endif
#ifdef MEDIA762_AU1E
                        F0771_FILE_Close(G3805_FileHandle);
#endif
                        if (L5786_ + L5787_ < 1) {
#ifdef MEDIA772_SU1E
                                F7072_GetDialogChoiceOrdinal(G3788_CAN_T_FIND_SAVED_GAME, C08_COLOR_RED | MASK0x8000_INVERT_BOX, G7060_OK, &G2263_s_Input_Dialog1Choice);
#endif
#ifdef MEDIA762_AU1E
                                F7074_DrawDialogErrorMessage(G3788_CAN_T_FIND_SAVED_GAME, C08_COLOR_RED | MASK0x8000_UNKNOWN);
#endif
                                M008_SET(L5783_, 0x8000);
                                L3936_i_ = 0;
                        } else {
                                if (L5786_ + L5787_ > 1) {
                                        L3937_ui_ = F7072_GetDialogChoiceOrdinal(G7085_LOAD_WHICH_SAVED_GAME, C15_COLOR_WHITE | MASK0x8000_INVERT_BOX, G7065_DUNGEON_MASTER_CHAOS_STRIKES_BACK_CANCEL, &G2255_s_Input_Dialog3ChoicesA);
                                        if (L3937_ui_ == 1) {
                                                goto loc_1A4C;
                                        }
                                        if (L3937_ui_ == 2) {
                                                L5785_pc_ = L5784_pc_;
                                                goto loc_1A4C;
                                        }
                                        L3936_i_ = G3807_ ? -99 : -1;
                                        goto loc_1D9A;
                                }
                                if (L5787_) {
                                        L5785_pc_ = L5784_pc_;
                                }
                                loc_1A4C:
#ifdef MEDIA772_SU1E
                                if ((G3805_FileHandle = Fopen(L5785_pc_, C0_READ_ONLY)) < 0) {
#endif
#ifdef MEDIA762_AU1E
                                if ((G3805_FileHandle = F0770_FILE_Open(L5785_pc_)) == NULL) {
#endif
                                        L3936_i_ = 0;
                                }
                        }
                }
        } while (L3936_i_ != 1);
#ifdef MEDIA762_AU1E
                F0774_FILE_Seek(G3805_FileHandle, 0L);
#endif
                F0088_strcpy(L3924_ps_->FileName, L5785_pc_);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                L3935_pc_TempBuffer = NULL;
                if (P3711_i_GameIndex) {
                        L3930_i_FileID = M740_FILE_ID_LOAD_MINI_DAT;
                } else {
                        L3937_ui_ = F7072_GetDialogChoiceOrdinal(G7085_LOAD_WHICH_SAVED_GAME, C15_COLOR_WHITE | MASK0x8000_INVERT_BOX, G7065_DUNGEON_MASTER_CHAOS_STRIKES_BACK_CANCEL, &G2255_s_Input_Dialog3ChoicesA);
                        L3932_ui_ = 0;
                        while (L3932_ui_ < 5) {
                                F7323_WaitVerticalBlank();
                                L3932_ui_++;
                        }
                        F7071_();
                        if (L3937_ui_ == 1) { /* Choice: Dungeon Master */
                                L3930_i_FileID = M741_FILE_ID_LOAD_DMSAVE_DAT;
                        } else {
                                if (L3937_ui_ == 2) { /* Choice: Chaos Strikes Back */
                                        L3930_i_FileID = M742_FILE_ID_LOAD_CSBGAME_DAT;
                                } else { /* Choice: Cancel */
                                        L3936_i_ = -3;
                                        goto loc_13733;
                                }
                        }
                }
                G7004_SavedGameFileHandle = F7132_(L3930_i_FileID);
                F7137_FileOperation(G7004_SavedGameFileHandle, 0xF002, 0);
#endif
                F7072_GetDialogChoiceOrdinal(P3711_i_GameIndex ? G7075_PLEASE_WAIT_LOADING_NEW_ADVENTURE : G7071_PLEASE_WAIT_LOADING_SAVED_GAME, C15_COLOR_WHITE, NULL, NULL);
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                L3933_c_ = C1_TRUE;
#endif
                L3924_ps_->KeyWordIndex = C29_CSB_SAVE_HEADER_DECRYPTION_KEY_INDEX;
                L3924_ps_->SaveHeaderFormat = C0x02_SAVE_HEADER_FORMAT_CHAOS_STRIKES_BACK;
#ifdef MEDIA773_SU1E_AU1E
                if (F1993_(&L3924_ps_->SaveHeader) == 0) {
                        goto loc_13733;
                }
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
                if (L3930_i_FileID == M740_FILE_ID_LOAD_MINI_DAT) {
                        F7137_FileOperation(G7004_SavedGameFileHandle, C0xF00A_OPERATION_READ, C16_FILEOP_BYTE_COUNT, (long)sizeof(int16_t), C15_FILEOP_SET_BUFFER, (long)&L6044_, 0);
                }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7137_FileOperation(G7004_SavedGameFileHandle, C0xF00A_OPERATION_READ, C16_FILEOP_BYTE_COUNT, (long)sizeof(CSB_SAVE_HEADER), C15_FILEOP_SET_BUFFER, (long)&L3924_ps_->SaveHeader, 0);
#endif
                F7317_MAIN_CopyBytes_Alt((char*)&L3924_ps_->SaveHeader, (char*)&L3927_s_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(DM_SAVE_HEADER));
                if (F7061_F0429_STARTEND_IsReadSaveHeaderSuccessful((int16_t*)&L3924_ps_->SaveHeader, L3924_ps_->KeyWordIndex) == 0) {
                        L3924_ps_->KeyWordIndex = C10_DM_SAVE_HEADER_DECRYPTION_KEY_INDEX;
                        L3924_ps_->SaveHeaderFormat = C0x01_SAVE_HEADER_FORMAT_DUNGEON_MASTER;
                        F7317_MAIN_CopyBytes_Alt((char*)&L3927_s_, (char*)&L3924_ps_->SaveHeader, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(DM_SAVE_HEADER));
                        if (F7061_F0429_STARTEND_IsReadSaveHeaderSuccessful((int16_t*)&L3924_ps_->SaveHeader, L3924_ps_->KeyWordIndex) == 0) {
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                L3924_ps_->SaveHeaderFormat = C0x00_SAVE_HEADER_FORMAT_INVALID;
                                L3936_i_ = -21;
#endif
                                goto loc_13733;
                        }
                }
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                F7054_DetermineGameFormats(L3924_ps_);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                if (P3711_i_GameIndex) {
                        if (!F7272_IsDungeonValid(L3924_ps_, 2)) {
                                L3936_i_ = -22;
                                goto loc_13733;
                        }
                } else {
                        if (!F7272_IsDungeonValid(L3924_ps_, 1)) {
                                L3936_i_ = -23;
                                goto loc_13733;
                        }
                }
#endif
                if (L3924_ps_->SaveHeaderFormat == C0x02_SAVE_HEADER_FORMAT_CHAOS_STRIKES_BACK) {
                        L3928_pui_ = L3926_ps_->Checksums;
                        L3929_pui_ = L3926_ps_->Keys;
                } else {
                        L3928_pui_ = L3924_ps_->SaveHeader.Checksums;
                        L3929_pui_ = L3924_ps_->SaveHeader.Keys;
                }
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                L3934_l_ = L3924_ps_->ChampionDataByteCount - sizeof(PARTY_INFO);
#endif
#ifdef MEDIA773_SU1E_AU1E
                if (F7057_ReadSaveGamePartWithChecksum((unsigned char*)&L3924_ps_->GlobalData, sizeof(GLOBAL_DATA), L3929_pui_[C0_SAVE_PART_GLOBAL_DATA], L3928_pui_[C0_SAVE_PART_GLOBAL_DATA]) == 0) {
                        goto loc_13733;
                }
#endif
#ifdef MEDIA772_SU1E
                L3924_ps_->ActiveGroups = (ACTIVE_GROUP*)F7023_Alloc((long)(L3924_ps_->GlobalData.MaximumActiveGroupCount * 16));
                L3924_ps_->Events = (EVENT*)F7023_Alloc((long)(L3924_ps_->GlobalData.EventMaximumCount * 10));
                L3924_ps_->TimeLine = (int16_t*)F7023_Alloc((long)(L3924_ps_->GlobalData.EventMaximumCount << 1));
#endif
#ifdef MEDIA762_AU1E
                L3924_ps_->ActiveGroups = (ACTIVE_GROUP*)F2095_AllocateMemory((long)(L3924_ps_->GlobalData.MaximumActiveGroupCount * 16));
                L3924_ps_->Events = (EVENT*)F2095_AllocateMemory((long)(L3924_ps_->GlobalData.EventMaximumCount * 10));
                L3924_ps_->TimeLine = (int16_t*)F2095_AllocateMemory((long)(L3924_ps_->GlobalData.EventMaximumCount << 1));
                L3924_ps_->Champions = (CHAMPION_EXCLUDING_PORTRAIT*)F2095_AllocateMemory(L3934_l_);
                L3935_pc_TempBuffer = (char*)F2095_AllocateMemory(L3924_ps_->ChampionDataByteCount);
                if (L3924_ps_->PortraitCount) {
                        L3924_ps_->Portraits = (unsigned char*)F2095_AllocateMemory(L3924_ps_->PortraitByteCount * L3924_ps_->PortraitCount);
                }
#endif
#ifdef MEDIA773_SU1E_AU1E
                if (F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3924_ps_->ActiveGroups, L3924_ps_->GlobalData.MaximumActiveGroupCount * 16, L3929_pui_[C1_SAVE_PART_ACTIVE_GROUP], L3928_pui_[C1_SAVE_PART_ACTIVE_GROUP]) == 0) {
                        goto loc_13733;
                }
#endif
#ifdef MEDIA772_SU1E
                if (F7057_ReadSaveGamePartWithChecksum((unsigned char*)&L3924_ps_->Party, sizeof(PARTY_INFO), L3929_pui_[C2_SAVE_PART_PARTY], L3928_pui_[C2_SAVE_PART_PARTY]) == 0) {
#endif
#ifdef MEDIA762_AU1E
                if (F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3935_pc_TempBuffer, (int16_t)L3924_ps_->ChampionDataByteCount, L3929_pui_[C2_SAVE_PART_PARTY], L3928_pui_[C2_SAVE_PART_PARTY]) == 0) {
#endif
#ifdef MEDIA773_SU1E_AU1E
                        goto loc_13733;
                }
#endif
#ifdef MEDIA772_SU1E
                for (L3936_i_ = 0; L3936_i_ < L3924_ps_->GlobalData.PartyChampionCount; L3936_i_++) {
                        for (L3937_ui_ = 0; L3937_ui_ < 8; L3937_ui_++) {
                                if (L3924_ps_->Party.Champions[L3936_i_].Name[L3937_ui_] == '\0') {
                                        break;
                                }
                        }
                        while (L3937_ui_ < 8) {
                                L3924_ps_->Party.Champions[L3936_i_].Name[L3937_ui_] = '\0';
                                L3937_ui_++;
                        }
                        for (L3937_ui_ = 0; L3937_ui_ < 20; L3937_ui_++) {
                                if (L3924_ps_->Party.Champions[L3936_i_].Title[L3937_ui_] == '\0') {
                                        break;
                                }
                        }
                        while (L3937_ui_ < 20) {
                                L3924_ps_->Party.Champions[L3936_i_].Title[L3937_ui_] = '\0';
                                L3937_ui_++;
                        }
                }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7057_ReadSaveGamePartWithChecksum((unsigned char*)&L3924_ps_->GlobalData, sizeof(GLOBAL_DATA), L3929_pui_[C0_SAVE_PART_GLOBAL_DATA], L3928_pui_[C0_SAVE_PART_GLOBAL_DATA]);
                L3924_ps_->ActiveGroups = (ACTIVE_GROUP*)F7023_Alloc((long)(L3924_ps_->GlobalData.MaximumActiveGroupCount * 16), MASK0x0400_MEMREQ);
                L3924_ps_->Events = (EVENT*)F7023_Alloc((long)(L3924_ps_->GlobalData.EventMaximumCount * 10), MASK0x0400_MEMREQ);
                L3924_ps_->TimeLine = (int16_t*)F7023_Alloc((long)(L3924_ps_->GlobalData.EventMaximumCount << 1), MASK0x0400_MEMREQ);
                L3924_ps_->Champions = (CHAMPION_EXCLUDING_PORTRAIT*)F7023_Alloc(L3934_l_, MASK0x0400_MEMREQ);
                L3935_pc_TempBuffer = (char*)F7023_Alloc(L3924_ps_->ChampionDataByteCount, MASK0x0400_MEMREQ);
                if (L3924_ps_->PortraitCount) {
                        L3924_ps_->Portraits = (unsigned char*)F7023_Alloc(L3924_ps_->PortraitByteCount * L3924_ps_->PortraitCount, MASK0x0400_MEMREQ);
                }
                F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3924_ps_->ActiveGroups, L3924_ps_->GlobalData.MaximumActiveGroupCount * 16, L3929_pui_[C1_SAVE_PART_ACTIVE_GROUP], L3928_pui_[C1_SAVE_PART_ACTIVE_GROUP]);
                F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3935_pc_TempBuffer, L3924_ps_->ChampionDataByteCount, L3929_pui_[C2_SAVE_PART_PARTY], L3928_pui_[C2_SAVE_PART_PARTY]);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                F7317_MAIN_CopyBytes_Alt((char*)L3935_pc_TempBuffer, (char*)L3924_ps_->Champions, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, L3934_l_);
                F7317_MAIN_CopyBytes_Alt((char*)((long)L3935_pc_TempBuffer + L3934_l_), (char*)&L3924_ps_->Party, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(PARTY_INFO));
#endif
#ifdef MEDIA773_SU1E_AU1E
                if (F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3924_ps_->Events, L3924_ps_->GlobalData.EventMaximumCount * 10, L3929_pui_[C3_SAVE_PART_EVENTS], L3928_pui_[C3_SAVE_PART_EVENTS]) == 0) {
                        goto loc_13733;
                }
                if (F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3924_ps_->TimeLine, L3924_ps_->GlobalData.EventMaximumCount << 1, L3929_pui_[C4_SAVE_PART_TIMELINE], L3928_pui_[C4_SAVE_PART_TIMELINE]) == 0) {
                        goto loc_13733;
                }
#endif
#ifdef MEDIA762_AU1E
                if (L3924_ps_->PortraitCount) {
                        if (!F0772_FILE_Read(G3805_FileHandle, L3924_ps_->PortraitByteCount * L3924_ps_->PortraitCount, L3924_ps_->Portraits)) {
                                goto loc_13733;
                        }
                }
                F7066_LoadPortraits(L3924_ps_);
                for (L3936_i_ = 0; L3936_i_ < L3924_ps_->GlobalData.PartyChampionCount; L3936_i_++) {
                        L6048_pc_ = (char*)F7067_GetChampionInfo(L3924_ps_, L3936_i_, C31_CHAMPION_INFO_PORTRAIT);
                        F2104_CHAMPION_ConvertBitmapToAtariSTPlanar(L6048_pc_, 32, 29);
                }
#endif
#ifdef MEDIA773_SU1E_AU1E
                if (F7063_LoadDungeon(L3924_ps_) == 0) {
                        goto loc_13733;
                }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3924_ps_->Events, L3924_ps_->GlobalData.EventMaximumCount * 10, L3929_pui_[C3_SAVE_PART_EVENTS], L3928_pui_[C3_SAVE_PART_EVENTS]);
                F7057_ReadSaveGamePartWithChecksum((unsigned char*)L3924_ps_->TimeLine, L3924_ps_->GlobalData.EventMaximumCount << 1, L3929_pui_[C4_SAVE_PART_TIMELINE], L3928_pui_[C4_SAVE_PART_TIMELINE]);
                if (L3924_ps_->PortraitCount) {
                        F7137_FileOperation(G7004_SavedGameFileHandle, C0xF00A_OPERATION_READ, C16_FILEOP_BYTE_COUNT, L3924_ps_->PortraitByteCount * L3924_ps_->PortraitCount, C15_FILEOP_SET_BUFFER, (long)L3924_ps_->Portraits, 0);
                }
                if (F7063_LoadDungeon(L3924_ps_) == 0) {
                        L3936_i_ = -1;
                } else {
#endif
#ifdef MEDIA675_F31E_F31J_X31J_P31J_AU1E
                        F7064_PadChampionNameAndTitle(P3711_i_GameIndex);
#endif
#ifdef MEDIA768_AU2E_AU3E
                        F7064_PadChampionNameAndTitle(L3924_ps_);
#endif
#ifdef MEDIA773_SU1E_AU1E
                        G3807_ = 0;
                        if (G7111_Games[P3711_i_GameIndex].GameLoaded) {
#endif
#ifdef MEDIA772_SU1E
                                F7053_FreeGame(&G7111_Games[P3711_i_GameIndex], P3711_i_GameIndex);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                F7053_FreeGame(&G7111_Games[P3711_i_GameIndex]);
#endif
#ifdef MEDIA773_SU1E_AU1E
                        }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3711_i_GameIndex == C0_GAME_SOURCE) {
                                G7114_LoadedChampionCount = 0;
                        }
                        F7066_LoadPortraits(L3924_ps_);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                        L3924_ps_->GameLoaded = C1_TRUE;
                        G7111_Games[P3711_i_GameIndex] = *L3924_ps_;
#endif
                        if (P3711_i_GameIndex == C0_GAME_SOURCE) {
                                G7114_LoadedChampionCount = L3924_ps_->GlobalData.PartyChampionCount;
                                F7077_InitCMPStructure();
                        }
#ifdef MEDIA772_SU1E
                        L3924_ps_->GameLoaded = C1_TRUE;
                        G7111_Games[P3711_i_GameIndex] = *L3924_ps_;
#endif
#ifdef MEDIA768_AU2E_AU3E
                        F2122_DecodeAllPortraitsWhileLoading(L3924_ps_);
#endif
#ifdef MEDIA773_SU1E_AU1E
        L3936_i_ = 1;
#endif
#ifdef MEDIA772_SU1E
        Fclose(G3805_FileHandle);
#endif
#ifdef MEDIA762_AU1E
        F0771_FILE_Close(G3805_FileHandle);
#endif
#ifdef MEDIA773_SU1E_AU1E
        loc_1D9A:
#endif
#ifdef MEDIA762_AU1E
        if (L3935_pc_TempBuffer) {
                F7024_Free(L3935_pc_TempBuffer);
                L3935_pc_TempBuffer = NULL;
        }
#endif
#ifdef MEDIA773_SU1E_AU1E
        F1992_RequestUtilityDiskInDrive();
        F7071_();
        return L3936_i_;
        loc_13733:
#endif
#ifdef MEDIA772_SU1E
        F7072_GetDialogChoiceOrdinal(P3711_i_GameIndex ? G3793_THE_NEW_ADVENTURE_IS_DAMAGED : G3790_SAVED_GAME_ERROR, C08_COLOR_RED, G7060_OK, &G2263_s_Input_Dialog1Choice);
        F7053_FreeGame(L3924_ps_, 0);
#endif
#ifdef MEDIA762_AU1E
        F7074_DrawDialogErrorMessage(P3711_i_GameIndex ? G3793_THE_NEW_ADVENTURE_IS_DAMAGED : G3790_SAVED_GAME_ERROR, C08_COLOR_RED);
        F7053_FreeGame(L3924_ps_);
#endif
#ifdef MEDIA773_SU1E_AU1E
        L3936_i_ = -1;
        goto loc_1D9A;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        L3937_ui_ = 1;
                        L3936_i_ = 0;
                }
        }
        loc_13733:
        if (L3935_pc_TempBuffer) {
                T7051001: /* ANOMALY_FMT Label required to disable optimization */
                F7024_Free(L3935_pc_TempBuffer);
                L3935_pc_TempBuffer = NULL;
        }
        if (G7004_SavedGameFileHandle != -1) {
                T7051002: /* ANOMALY_FMT Label required to disable optimization */
                F7135_(G7004_SavedGameFileHandle);
                G7004_SavedGameFileHandle = -1;
        }
        if (L3936_i_ >= 0) {
                L3936_i_ = 1;
        } else {
                if ((L3936_i_ != -2) && (L3936_i_ != -1) && (L3936_i_ != -3)) {
                        if (L3933_c_) {
                                F7071_();
                                L3933_c_ = C0_FALSE;
                                F7074_DrawDialogErrorMessage(G7082_INCORRECT_OR_DAMAGED_SAVED_GAME, C08_COLOR_RED);
                        }
                        L3936_i_ = -1;
                }
        }
        if (L3936_i_ != 1) {
                F7053_FreeGame(L3924_ps_);
        }
        if (L3933_c_) {
                F7071_();
                L3933_c_ = C0_FALSE;
        }
        F7111_RestorePreviousProgramState();
        return L3936_i_;
#endif
}
#endif
