Newer
Older
AMI-Aptio-BIOS-Reversed / MdeModulePkg / Core / Pei / PeiMain / RomLayoutPei / RomLayoutPei.c
@Ajax Dong Ajax Dong 2 days ago 52 KB Restructure the repo
/*
 *RomLayoutPei.c - Decompiled source for RomLayoutPei.efi
 *
 *Copyright (c) HR650X BIOS Decompilation Project
 */

#include "RomLayoutPei.h"

char *CopyMem(char *dst, char *src, unsigned int count)
{
 unsigned int count_1; // edx char *dst_1; // edi char *src_1; // esi count_1 = count; /*0xffc00ca6*/
 if ( src < dst && &src[count - 1] >= dst ) /*0xffc00cb4*/
 {
 src_1 = &src[count - 1]; /*0xffc00cc8*/
 dst_1 = &dst[count - 1]; /*0xffc00cca*/
 }
 else
 {
 count_1 = count & 3; /*0xffc00cb8*/
 qmemcpy(dst, src, 4 * (count >> 2)); /*0xffc00cc1*/
 src_1 = &src[4 * (count >> 2)]; /*0xffc00cc1*/
 dst_1 = &dst[4 * (count >> 2)]; /*0xffc00cc1*/
 }
 qmemcpy(dst_1, src_1, count_1); /*0xffc00cd1*/
 return dst; /*0xffc00cd8*/
}

void *ZeroMem(void *buf, unsigned int count)
{
 memset(buf, 0, count); /*0xffc00cf3*/
 return buf; /*0xffc00cfa*/
}

void *SetMem(void *buf, unsigned int count, char value)
{
 memset(buf, value, count); /*0xffc00d09*/
 return buf; /*0xffc00d0f*/
}

int SetMem32(int a1, int a2, int a3, int a4)
{
 do /*0xffc00d35*/
 {
 *(_DWORD *)(a1 + 8 *a2 - 8) = a3; /*0xffc00d2d*/
 *(_DWORD *)(a1 + 8 *a2-- - 4) = a4; /*0xffc00d31*/
 }
 while ( a2 ); /*0xffc00d35*/
 return a1; /*0xffc00d39*/
}

void *SetMem64(void *buf, unsigned int count, int value)
{
 memset32(buf, value, count); /*0xffc00d49*/
 return buf; /*0xffc00d4f*/
}

EFI_STATUS ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
 int Table; // ecx _BYTE *v3; // eax if ( *(char *)(GetPcdToken() + 1024068) >= 0 ) /*0xffc00de9*/
 {
 SetIoPort80(); /*0xffc00deb*/
 v3 = (_BYTE *)(GetPcdToken() + 1024068); /*0xffc00df5*/
 LOBYTE(Table) = *v3 | 0x80; /*0xffc00df9*/
 *v3 = Table; /*0xffc00dfc*/
 }
 return RomLayoutPeiEntry(Table, (int)SystemTable); /*0xffc00e02*/
}

char FvProcessFile(int FvIndex, _DWORD *FileContext, int FvBase)
{
 char ContinueFlag; // dl int *PreProcessTable; // edi int TableIndex; // edi int *PostProcessTable; // eax int NextOffset; // eax int FileOffset; // [esp+10h] [ebp-1Ch] BYREF int NextOffset_1; // [esp+14h] [ebp-18h]
 int FileType; // [esp+18h] [ebp-14h]
 int FileAttributes; // [esp+1Ch] [ebp-10h]
 int FileState; // [esp+20h] [ebp-Ch]
 int ReservedField; // [esp+24h] [ebp-8h]

 ContinueFlag = 1; /*0xffc00e1c*/
 if ( dword_FFC03330 ) /*0xffc00e1e*/
 {
 PreProcessTable = &dword_FFC03330; /*0xffc00e20*/
 while ( ContinueFlag ) /*0xffc00e27*/
 {
 ContinueFlag = ((int ( *)(int, _DWORD *, int))*PreProcessTable)(FvIndex, FileContext, FvBase); /*0xffc00e34*/
 if ( !ContinueFlag ) /*0xffc00e3b*/
 break; /*0xffc00e3b*/
 if ( !*++PreProcessTable ) /*0xffc00e44*/
 goto LABEL_6; /*0xffc00e47*/
 }
 }
 else
 {
LABEL_6:
 TableIndex = 0; /*0xffc00e49*/
 FileOffset = FileContext[4]; /*0xffc00e4e*/
 NextOffset_1 = FileContext[5]; /*0xffc00e54*/
 FileType = FileContext[6]; /*0xffc00e5a*/
 FileAttributes = FileContext[7]; /*0xffc00e60*/
 FileState = FileContext[8]; /*0xffc00e66*/
 ReservedField = FileContext[9]; /*0xffc00e6c*/
 if ( ::PostProcessTable[0] ) /*0xffc00e75*/
 {
 PostProcessTable = ::PostProcessTable; /*0xffc00e77*/
 do /*0xffc00ed9*/
 {
 ContinueFlag = ((int ( *)(int, int *, int))*PostProcessTable)(FvIndex, &FileOffset, FvBase); /*0xffc00e86*/
 if ( !ContinueFlag ) /*0xffc00e8d*/
 break; /*0xffc00e8d*/
 NextOffset = NextOffset_1; /*0xffc00e92*/
 if ( FileOffset != FileContext[4] || NextOffset_1 != FileContext[5] ) /*0xffc00e9d*/
 {
 FileContext[4] = FileOffset; /*0xffc00e9f*/
 FileContext[5] = NextOffset; /*0xffc00ea2*/
 }
 if ( FileType != FileContext[6] ) /*0xffc00eab*/
 FileContext[6] = FileType; /*0xffc00ead*/
 if ( FileAttributes != FileContext[7] ) /*0xffc00eb6*/
 FileContext[7] = FileAttributes; /*0xffc00eb8*/
 if ( FileState != FileContext[8] ) /*0xffc00ec1*/
 FileContext[8] = FileState; /*0xffc00ec3*/
 if ( ReservedField != FileContext[9] ) /*0xffc00ecc*/
 FileContext[9] = ReservedField; /*0xffc00ece*/
 PostProcessTable = &::PostProcessTable[++TableIndex]; /*0xffc00ed2*/
 }
 while ( *PostProcessTable ); /*0xffc00ed9*/
 }
 }
 return ContinueFlag; /*0xffc00ede*/
}

_WORD *AmiRomLayoutInitHob()
{
 _WORD *HobList; // eax _WORD *i; // eax _WORD *j_1; // edx _WORD *j; // edx int v4; // edx _WORD *result; // eax HobList = (_WORD *)GetHobList(); /*0xffc00ee8*/
 for ( i = GetNextHobByType(5, HobList); i; i = GetNextHobByType(5, j_1) ) /*0xffc00ef2*/
 {
 j_1 = (_WORD *)((char *)i + (unsigned __int16)i[1]); /*0xffc00f04*/
 *i = -2; /*0xffc00f06*/
 }
 for ( j = (_WORD *)GetHobList(); ; j = (_WORD *)((char *)result + v4) ) /*0xffc00f18*/
 {
 result = GetNextHobByType(9, j); /*0xffc00f28*/
 if ( !result ) /*0xffc00f2f*/
 break; /*0xffc00f2f*/
 v4 = (unsigned __int16)result[1]; /*0xffc00f1c*/
 *result = -2; /*0xffc00f20*/
 }
 return result; /*0xffc00f31*/
}

char VerifyFvAlignment(int a1, int a2)
{
 char *src; // edi unsigned int Buffer; // esi unsigned int Unaligned64; // ebp char *AlignedPages; // eax char *AlignedPages_1; // esi src = *(char **)(a2 + 16); /*0xffc00f3c*/
 Buffer = 1 << (((unsigned int)ReadUnaligned32(src + 44) >> 16) & 0x1F); /*0xffc00f52*/
 if ( Buffer < 8 ) /*0xffc00f57*/
 Buffer = 8; /*0xffc00f5b*/
 if ( (unsigned int)src % Buffer )
 {
 DebugPrint(64, (int)"VerifyFvAlignment: FV is not aligned, allocating aligned buffer \n\r");
 Unaligned64 = ReadUnaligned64(src + 32); /*0xffc00f7a*/
 AlignedPages = (char *)AllocateAlignedPages((Unaligned64 >> 12) + ((Unaligned64 & 0xFFF) != 0), Buffer); /*0xffc00f92*/
 AlignedPages_1 = AlignedPages; /*0xffc00f97*/
 if ( !AlignedPages )
 {
 DebugPrint(0x80000000, (int)"VerifyFvAlignment: ERROR: New buffer allocation failed!!\n\r");
 return 0; /*0xffc00fb3*/
 }
 if ( Unaligned64 ) /*0xffc00fb7*/
 CopyMemS(AlignedPages, src, Unaligned64); /*0xffc00fbe*/
 *(_DWORD *)(a2 + 20) = 0; /*0xffc00fc4*/
 *(_DWORD *)(a2 + 16) = AlignedPages_1; /*0xffc00fcf*/
 DebugPrint(64, (int)"VerifyFvAlignment: Allocation successful.\n\r");
 }
 return 1; /*0xffc00fdb*/
}

int ValidateAndProcessFv(int RomBase, int *dst)
{
 int v4; // [esp-4h] [ebp-8h]

 if ( FvProcessFile(RomBase, dst, dst[9]) && VerifyFvAlignment(v4, (int)dst) ) /*0xffc00ffc*/
 return ProcessFvHob(dst); /*0xffc01008*/
 else return -2147483638; /*0xffc00ff3*/
}

int __thiscall ReportCorruptFvAndRecover(void *this)
{
 int result; // eax int Result; // [esp+4h] [ebp-4h] BYREF result = (*(int ( **)(void *, int *))(*(_DWORD *)this + 40))(this, &Result); /*0xffc0101b*/
 if ( result < 0 || Result != 32 ) /*0xffc01028*/
 {
 (*(void ( **)(void *, int))(*(_DWORD *)this + 44))(this, 32); /*0xffc0102f*/
 (*(void ( **)(void *, void *))(*(_DWORD *)this + 24))(this, &unk_FFC032FC); /*0xffc0103a*/
 return (*(int ( **)(void *, int, int, _DWORD, _DWORD, _DWORD))(*(_DWORD *)this + 88))( /*0xffc0104c*/
 this,
 1,
 50532356,
 0,
 0,
 0);
 }
 return result; /*0xffc01052*/
}

int RomLayoutPeiEntryRecovery(void *PeiServices)
{
 int BootModeStatus; // eax int PerfToken; // ecx char *FvCachePtr; // eax char *i; // edi int PerfToken_1; // [esp-4h] [ebp-44h]
 int PerfToken_2; // [esp-4h] [ebp-44h]
 int BootMode; // [esp+Ch] [ebp-34h] BYREF char *AllocatedBuffer[2]; // [esp+10h] [ebp-30h] BYREF char FvInfo[16]; // [esp+18h] [ebp-28h] BYREF char *FvBase; // [esp+28h] [ebp-18h]
 char *FvAllocEnd; // [esp+2Ch] [ebp-14h]
 unsigned int RegionSize; // [esp+34h] [ebp-Ch]
 char v14; // [esp+3Ch] [ebp-4h]

 BootModeStatus = (*(int ( **)(void *, int *))(*(_DWORD *)PeiServices + 40))(PeiServices, &BootMode); /*0xffc0106d*/
 PerfToken = PerfToken_1; /*0xffc01071*/
 if ( BootModeStatus < 0 )
 {
 DebugPrint(2, (int)"WARNING: Unable to determine BootMode\n");
 BootMode = 0; /*0xffc01082*/
 PerfToken = PerfToken_2; /*0xffc01088*/
 }
 PerformanceStart(PerfToken, "PRL-AM"); /*0xffc01093*/
 for ( FvCachePtr = (char *)FvCacheGetFirst(); ; FvCachePtr = (char *)FvCacheGetNext(i) )
 {
 i = FvCachePtr; /*0xffc01168*/
 if ( !FvCachePtr ) /*0xffc0116c*/
 break; /*0xffc0116c*/
 CopyMemS(FvInfo, FvCachePtr, 0x28u); /*0xffc010ad*/
 if ( (v14 & 0x20) == 0 ) /*0xffc010b8*/
 {
 if ( (v14 & 4) == 0 || (v14 & 2) != 0 ) /*0xffc01128*/
 continue; /*0xffc01128*/
 goto LABEL_12; /*0xffc01128*/
 }
 if ( BootMode == 17 ) /*0xffc010bf*/
 continue; /*0xffc010bf*/
 if ( (*(int ( **)(void *, int, unsigned int, char **))(*(_DWORD *)PeiServices + 72))( /*0xffc010ef*/
 PeiServices,
 4,
 (RegionSize >> 12) + ((RegionSize & 0xFFF) != 0),
 AllocatedBuffer) >= 0 )
 {
 if ( RegionSize ) /*0xffc010f6*/
 CopyMemS(AllocatedBuffer[0], FvBase, RegionSize); /*0xffc01104*/
 FvBase = AllocatedBuffer[0]; /*0xffc0110e*/
 FvAllocEnd = AllocatedBuffer[1]; /*0xffc01116*/
LABEL_12:
 if ( ValidateAndProcessFv((int)PeiServices, FvInfo) >= 0 ) /*0xffc01137*/
 continue; /*0xffc01137*/
 }
 if ( v14 >= 0 )
 {
 DebugPrint(0x80000000, (int)"ERROR: Corrupt FirmwareVolume at address 0x%p\n", FvBase);
 ReportCorruptFvAndRecover(PeiServices); /*0xffc0115c*/
 }
 }
 PerformanceEnd(); /*0xffc01177*/
 return 0; /*0xffc01181*/
}

int ProcessRomLayout(int IsRecovery, void *RomBase)
{
 void *RomBase_1; // ebp int Status; // esi _WORD *HobList; // eax _WORD *NextGuidHob; // eax unsigned int EntrySize; // ebp unsigned int *HobHeader; // eax char *HobData; // esi char *src_1; // ebx char *SrcPtr_1; // ecx char *OffsetAdjust; // ecx char *FvCacheEntry; // esi int DebugOutputPtr; // eax int DebugOutput; // eax int TotalSize; // [esp-8h] [ebp-64h]
 int TotalSize_1; // [esp+14h] [ebp-48h] BYREF void *RomBase_2; // [esp+18h] [ebp-44h]
 unsigned int EntryCount; // [esp+1Ch] [ebp-40h] BYREF unsigned int SrcPtr; // [esp+20h] [ebp-3Ch] BYREF char *src[3]; // [esp+24h] [ebp-38h] BYREF char dst[16]; // [esp+30h] [ebp-2Ch] BYREF const void *FvBaseAddr; // [esp+40h] [ebp-1Ch]
 int Pad; // [esp+44h] [ebp-18h]
 int RegionOffset; // [esp+48h] [ebp-14h]
 char FvFlags; // [esp+54h] [ebp-8h]

 RomBase_1 = RomBase; /*0xffc01190*/
 RomBase_2 = RomBase; /*0xffc01195*/
 src[0] = 0; /*0xffc01199*/
 SrcPtr = 0; /*0xffc0119d*/
 EntryCount = 0; /*0xffc011a1*/
 TotalSize_1 = 0; /*0xffc011a5*/
 if ( IsRecovery )
 {
 Status = FindRomLayoutMarker(src, &SrcPtr, &EntryCount, &TotalSize_1); /*0xffc011ca*/
 if ( Status < 0 )
 {
 DebugPrint(0x80000000, (int)"ERROR: ROM Layout is not found in the Recovery Image\n");
 DebugPrint(0x80000000, (int)" Recovery will fail and boot will be attempted using current ROM image\n"); /*0xffc011e9*/
 return Status; /*0xffc011f3*/
 }
 AmiRomLayoutInitHob(); /*0xffc011f8*/
 HobList = (_WORD *)GetHobList(); /*0xffc011fd*/
 NextGuidHob = GetNextGuidHob((int)&MarkerGuid_0, HobList); /*0xffc0120b*/
 EntrySize = EntryCount; /*0xffc01210*/
 TotalSize = TotalSize_1; /*0xffc0121a*/
 *NextGuidHob = -2; /*0xffc0121e*/
 EntryCount = DivU64x32(TotalSize, 0); /*0xffc0122a*/
 src[1] = (char *)48; /*0xffc0122e*/
 src[2] = 0; /*0xffc01236*/
 HobHeader = (unsigned int *)BuildGuidHob((int)&MarkerGuid_0, 48 *EntryCount + 16); /*0xffc01250*/
 if ( HobHeader ) /*0xffc01257*/
 {
 HobData = (char *)(HobHeader + 4); /*0xffc0125d*/
 src_1 = src[0]; /*0xffc01260*/
 *HobHeader = SrcPtr; /*0xffc01264*/
 SrcPtr_1 = &src_1[TotalSize_1]; /*0xffc0126a*/
 HobHeader[1] = EntrySize; /*0xffc0126c*/
 HobHeader[2] = 48; /*0xffc0126f*/
 HobHeader[3] = 1; /*0xffc01276*/
 SrcPtr = (unsigned int)SrcPtr_1; /*0xffc0127d*/
 if ( src_1 < SrcPtr_1 ) /*0xffc01283*/
 {
 OffsetAdjust = (char *)(16 - (_DWORD)HobHeader); /*0xffc01288*/
 src[0] = (char *)(16 - (_DWORD)HobHeader); /*0xffc0128a*/
 do /*0xffc012b6*/
 {
 if ( EntrySize ) /*0xffc01290*/
 {
 CopyMemS(HobData + 8, src_1, EntrySize); /*0xffc01298*/
 OffsetAdjust = src[0]; /*0xffc0129e*/
 }
 *((_DWORD *)HobData + 1) = 0; /*0xffc012a2*/
 src_1 += EntrySize; /*0xffc012ab*/
 *(_DWORD *)HobData = &HobData[(_DWORD)OffsetAdjust + 8]; /*0xffc012ad*/
 HobData += 48; /*0xffc012af*/
 }
 while ( (unsigned int)src_1 < SrcPtr ); /*0xffc012b6*/
 }
 }
 RomBase_1 = RomBase_2; /*0xffc012b8*/
 }
 for ( FvCacheEntry = (char *)FvCacheGetFirst(); FvCacheEntry; FvCacheEntry = (char *)FvCacheGetNext(FvCacheEntry) )
 {
 CopyMemS(dst, FvCacheEntry, 0x28u); /*0xffc012d8*/
 if ( IsRecovery ) /*0xffc012e0*/
 {
 Pad = 0; /*0xffc012e8*/
 FvBaseAddr = (const void *)(IsRecovery + RegionOffset); /*0xffc012ed*/
 }
 if ( (FvFlags & 8) != 0 )
 {
 if ( IsRecovery )
 {
 if ( ValidateAndProcessFv((int)RomBase_1, dst) ) /*0xffc01346*/
 {
 DebugOutputPtr = GetDebugOutput(); /*0xffc0134f*/
 if ( DebugOutputPtr ) /*0xffc01356*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc01362*/
 "e:\\hs\\AmiModulePkg\\RomLayout\\RomLayoutPei.c",
 490,
 "Status == 0");
 }
 }
 else if ( (FvFlags & 0x26) == 0 && ValidateAndProcessFv((int)RomBase_1, dst) < 0 && FvFlags >= 0 )
 {
 DebugPrint(0x80000000, (int)"ERROR: Corrupt FirmwareVolume at address 0x%p\n", FvBaseAddr);
 ReportCorruptFvAndRecover(RomBase_1); /*0xffc01339*/
 }
 }
 else if ( IsRecovery ) /*0xffc01366*/
 {
 if ( (FvFlags & 0x26) != 0 ) /*0xffc0136d*/
 {
 if ( ValidateAndProcessFv((int)RomBase_1, dst) ) /*0xffc01375*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc0137e*/
 if ( DebugOutput ) /*0xffc01385*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01396*/
 "e:\\hs\\AmiModulePkg\\RomLayout\\RomLayoutPei.c",
 503,
 "Status == 0");
 }
 }
 }
 }
 return 0; /*0xffc013af*/
}

char *CollectFvHandlers()
{
 char *i; // eax char *i_1; // esi unsigned int v2; // [esp+8h] [ebp-8h] BYREF unsigned int v3; // [esp+Ch] [ebp-4h] BYREF i = (char *)FvCacheGetEntryInfo(&v2, &v3); /*0xffc013c5*/
 if ( (int)i >= 0 ) /*0xffc013cd*/
 {
 i = (char *)BuildGuidHob((int)&MarkerGuid_1, 24 * (v3 / v2 + 1)); /*0xffc013e0*/
 i_1 = i; /*0xffc013e5*/
 if ( i ) /*0xffc013e9*/
 {
 i = (char *)FvCacheGetFirst(); /*0xffc013eb*/
 while ( i ) /*0xffc01423*/
 {
 *(_DWORD *)i_1 = *((_DWORD *)i + 4); /*0xffc013f5*/
 *((_DWORD *)i_1 + 1) = *((_DWORD *)i + 5); /*0xffc013fa*/
 *((_DWORD *)i_1 + 5) = *((_DWORD *)i + 9); /*0xffc01402*/
 *((_DWORD *)i_1 + 2) = *((_DWORD *)i + 6); /*0xffc01408*/
 *((_DWORD *)i_1 + 3) = *((_DWORD *)i + 7); /*0xffc0140e*/
 *((_DWORD *)i_1 + 4) = *((_DWORD *)i + 8); /*0xffc01414*/
 i = (char *)FvCacheGetNext(i); /*0xffc01417*/
 i_1 += 24; /*0xffc0141c*/
 }
 *(_DWORD *)i_1 = 0; /*0xffc01425*/
 *((_DWORD *)i_1 + 1) = 0; /*0xffc01427*/
 *((_DWORD *)i_1 + 5) = 0; /*0xffc0142a*/
 *((_DWORD *)i_1 + 2) = 0; /*0xffc0142d*/
 *((_DWORD *)i_1 + 3) = 0; /*0xffc01430*/
 *((_DWORD *)i_1 + 4) = 0; /*0xffc01433*/
 }
 }
 return i; /*0xffc01436*/
}

int RomLayoutPeiEntryStandard(void *PeiServices2)
{
 int PerfToken; // ecx int PeiServices; // eax int BootModeStatus; // eax int DebugOutputPtr; // eax int EntryStatus; // eax _WORD *FvHob; // eax int StatusRecovery; // edi int StatusNormal; // esi int BootMode; // [esp+10h] [ebp-8h] BYREF _WORD *HobList; // [esp+14h] [ebp-4h] BYREF HobList = 0; /*0xffc01453*/
 PerformanceStart(PerfToken, "PRL-DX"); /*0xffc01457*/
 PeiServices = GetPeiServices(); /*0xffc0145c*/
 BootModeStatus = (*(int ( **)(int, int *))(*(_DWORD *)PeiServices + 40))(PeiServices, &BootMode); /*0xffc01469*/
 if ( BootModeStatus < 0 ) /*0xffc01471*/
 {
 DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", BootModeStatus); /*0xffc0147e*/
 DebugOutputPtr = GetDebugOutput(); /*0xffc01486*/
 if ( DebugOutputPtr ) /*0xffc0148d*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc0149e*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 216,
 "!EFI_ERROR (Status)");
 }
 if ( BootMode != 32 && BootMode != 18 ) /*0xffc014b3*/
 goto LABEL_13; /*0xffc014b3*/
 EntryStatus = (*(int ( **)(void *, _WORD **))(*(_DWORD *)PeiServices2 + 48))(PeiServices2, &HobList); /*0xffc014bd*/
 if ( EntryStatus < 0 ) /*0xffc014c4*/
 return EntryStatus; /*0xffc014c4*/
 FvHob = GetNextGuidHob((int)&unk_FFC0323C, HobList); /*0xffc014cf*/
 if ( FvHob && !*((_BYTE *)FvHob + 32) && *((_QWORD *)FvHob + 3) ) /*0xffc014dd*/
 {
 StatusRecovery = ProcessRomLayout(*((_DWORD *)FvHob + 6), PeiServices2); /*0xffc014ef*/
 CollectFvHandlers(); /*0xffc014f1*/
 if ( StatusRecovery < 0 ) /*0xffc014f8*/
 (*(void ( **)(void *, int, int, _DWORD, _DWORD, _DWORD))(*(_DWORD *)PeiServices2 + 88))( /*0xffc0150a*/
 PeiServices2,
 -2147483646,
 50532359,
 0,
 0,
 0);
 return StatusRecovery; /*0xffc01510*/
 }
 else
 {
LABEL_13:
 StatusNormal = ProcessRomLayout(0, PeiServices2); /*0xffc0151d*/
 CollectFvHandlers(); /*0xffc0151f*/
 PerformanceEnd(); /*0xffc01529*/
 return StatusNormal; /*0xffc01531*/
 }
}

int RomLayoutPeiEntry(int PerfToken, void *SystemTable)
{
 char *i; // eax char *i_1; // edi char dst[36]; // [esp+10h] [ebp-28h] BYREF char v7; // [esp+34h] [ebp-4h]

 PerformanceStart(PerfToken, "PRL-Ent"); /*0xffc01552*/
 for ( i = (char *)FvCacheGetFirst(); ; i = (char *)FvCacheGetNext(i_1) ) /*0xffc0155a*/
 {
 i_1 = i; /*0xffc015a1*/
 if ( !i ) /*0xffc015a5*/
 break; /*0xffc015a5*/
 CopyMemS(dst, i, 0x28u); /*0xffc01569*/
 if ( (v7 & 2) != 0 && (v7 & 0x20) == 0 && ValidateAndProcessFv((int)SystemTable, (int *)dst) < 0 && v7 >= 0 ) /*0xffc01591*/
 ReportCorruptFvAndRecover(SystemTable); /*0xffc01595*/
 }
 PerformanceEnd(); /*0xffc015ac*/
 (*(void ( **)(void *, void *))(*(_DWORD *)SystemTable + 36))(SystemTable, &unk_FFC03324); /*0xffc015bc*/
 return (*(int ( **)(void *, void *))(*(_DWORD *)SystemTable + 36))(SystemTable, &unk_FFC03318); /*0xffc015cd*/
}

int __thiscall ReadUnaligned32(void *this)
{
 int DebugOutput; // eax if ( !this ) /*0xffc015d9*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc015db*/
 if ( DebugOutput ) /*0xffc015e2*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc015f3*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
 141,
 "Buffer != ((void *) 0)");
 }
 return *(_DWORD *)this; /*0xffc015fb*/
}

__int64 __thiscall ReadUnaligned64(void *this)
{
 int DebugOutput; // eax if ( !this ) /*0xffc01602*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc01604*/
 if ( DebugOutput ) /*0xffc0160b*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc0161c*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
 192,
 "Buffer != ((void *) 0)");
 }
 return *(_QWORD *)this; /*0xffc01627*/
}

int WriteUnaligned64(int a1, int a2)
{
 _DWORD *v2; // ecx _DWORD *v3; // esi int DebugOutput; // eax v3 = v2; /*0xffc0162a*/
 if ( !v2 ) /*0xffc0162e*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc01630*/
 if ( DebugOutput ) /*0xffc01637*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01648*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
 219,
 "Buffer != ((void *) 0)");
 }
 *v3 = a1; /*0xffc01656*/
 v3[1] = a2; /*0xffc01658*/
 return a1; /*0xffc0165b*/
}

int DivU64x32(int TotalSize, unsigned int a2)
{
 unsigned int v2; // ecx int DebugOutput; // eax unsigned __int64 Size; // rtt unsigned int v6; // [esp+0h] [ebp-4h]

 v6 = v2; /*0xffc0165e*/
 if ( !v2 ) /*0xffc01663*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc01665*/
 if ( DebugOutput ) /*0xffc0166c*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc0167a*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\DivU64x32.c",
 43,
 "Divisor != 0");
 }
 LODWORD(Size) = TotalSize; /*0xffc01690*/
 HIDWORD(Size) = a2 % v6; /*0xffc01690*/
 return Size / v6; /*0xffc01694*/
}

unsigned int __usercall AllocateAlignedPages@<eax>(unsigned int Pages@<edx>, unsigned int Alignment)
{
 int AlignMask; // ebx int DebugOutputPtr; // eax unsigned int Pages_1; // esi int DebugOutput; // eax int PeiServices; // eax int AlignedAddr; // ebp unsigned int PrefixPages; // ebx int FreeStatus; // eax int DebugPtr2; // eax int FreeStatus2; // eax int DebugPtr3; // eax int PeiServices2; // eax unsigned int AllocatedAddr; // [esp+10h] [ebp-8h] BYREF int AlignmentPages; // [esp+14h] [ebp-4h]

 AlignMask = Alignment - 1; /*0xffc016a6*/
 if ( ((Alignment - 1) & Alignment) != 0 ) /*0xffc016ab*/
 {
 DebugOutputPtr = GetDebugOutput(); /*0xffc016ad*/
 if ( DebugOutputPtr ) /*0xffc016b4*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc016c1*/
 "e:\\hs\\MdePkg\\Library\\PeiMemoryAllocationLib\\MemoryAllocationLib.c",
 194,
 "(Alignment & (Alignment - 1)) == 0");
 }
 if ( !Pages ) /*0xffc016c9*/
 return 0; /*0xffc016c9*/
 if ( Alignment > 0x1000 ) /*0xffc016d8*/
 {
 Pages_1 = Pages + ((Alignment & 0xFFF) != 0) + (Alignment >> 12); /*0xffc016f0*/
 if ( Pages_1 <= Pages ) /*0xffc016f4*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc016f6*/
 if ( DebugOutput ) /*0xffc016fd*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc0170a*/
 "e:\\hs\\MdePkg\\Library\\PeiMemoryAllocationLib\\MemoryAllocationLib.c",
 208,
 "RealPages > Pages");
 }
 PeiServices = GetPeiServices(); /*0xffc01710*/
 if ( (*(int ( **)(int, int, unsigned int, unsigned int *))(*(_DWORD *)PeiServices + 72))( /*0xffc01728*/
 PeiServices,
 4,
 Pages_1,
 &AllocatedAddr) >= 0 )
 {
 AlignedAddr = ~AlignMask & (AllocatedAddr + AlignMask); /*0xffc01733*/
 PrefixPages = ((AlignedAddr - AllocatedAddr) >> 12) /*0xffc0174a*/
 + (((((unsigned __int16)~(_WORD)AlignMask & (unsigned __int16)(AllocatedAddr + AlignMask))
 - (_WORD)AllocatedAddr)
 & 0xFFF) != 0);
 if ( PrefixPages ) /*0xffc0174c*/
 {
 FreeStatus = PeiFreePages(AllocatedAddr, AlignmentPages); /*0xffc01755*/
 if ( FreeStatus < 0 ) /*0xffc0175e*/
 {
 DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", FreeStatus); /*0xffc0176b*/
 DebugPtr2 = GetDebugOutput(); /*0xffc01773*/
 if ( DebugPtr2 ) /*0xffc0177a*/
 (*(void ( **)(const char *, int, const char *))(DebugPtr2 + 4))( /*0xffc0178b*/
 "e:\\hs\\MdePkg\\Library\\PeiMemoryAllocationLib\\MemoryAllocationLib.c",
 221,
 "!EFI_ERROR (Status)");
 }
 }
 AlignmentPages = 0; /*0xffc01791*/
 AllocatedAddr = AlignedAddr + (Pages << 12); /*0xffc0179f*/
 if ( ((Alignment & 0xFFF) != 0) + (Alignment >> 12) != PrefixPages ) /*0xffc017a3*/
 {
 FreeStatus2 = PeiFreePages(AlignedAddr + (Pages << 12), 0); /*0xffc017ac*/
 if ( FreeStatus2 < 0 ) /*0xffc017b5*/
 {
 DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", FreeStatus2); /*0xffc017c2*/
 DebugPtr3 = GetDebugOutput(); /*0xffc017ca*/
 if ( DebugPtr3 ) /*0xffc017d1*/
 (*(void ( **)(const char *, int, const char *))(DebugPtr3 + 4))( /*0xffc017e2*/
 "e:\\hs\\MdePkg\\Library\\PeiMemoryAllocationLib\\MemoryAllocationLib.c",
 230,
 "!EFI_ERROR (Status)");
 }
 }
 return AlignedAddr; /*0xffc017e8*/
 }
 return 0; /*0xffc016cd*/
 }
 PeiServices2 = GetPeiServices(); /*0xffc017ea*/
 if ( (*(int ( **)(int, int, unsigned int, unsigned int *))(*(_DWORD *)PeiServices2 + 72))( /*0xffc01802*/
 PeiServices2,
 4,
 Pages,
 &AllocatedAddr) < 0 )
 return 0; /*0xffc01802*/
 return AllocatedAddr; /*0xffc0180e*/
}

int __thiscall InternalAllocatePages(void *this)
{
 int PeiServices; // eax int Result; // [esp+4h] [ebp-4h] BYREF PeiServices = GetPeiServices(); /*0xffc0181c*/
 if ( (*(int ( **)(int, void *, int *))(*(_DWORD *)PeiServices + 76))(PeiServices, this, &Result) >= 0 ) /*0xffc01832*/
 return Result; /*0xffc01838*/
 else return 0; /*0xffc01834*/
}

int GetDebugOutput()
{
 int PeiServices; // eax int v2; // [esp+0h] [ebp-8h] BYREF int Result; // [esp+4h] [ebp-4h] BYREF PeiServices = GetPeiServices(); /*0xffc01844*/
 if ( (*(int ( **)(int, void *, _DWORD, int *, int *))(*(_DWORD *)PeiServices + 32))( /*0xffc01863*/
 PeiServices,
 &unk_FFC0324C,
 0,
 &v2,
 &Result) >= 0 )
 return Result; /*0xffc01869*/
 else return 0; /*0xffc01865*/
}

int DebugPrint(int a1, int a2, ...)
{
 int result; // eax int ( **v3)(int, int, char *); // esi va_list va; // [esp+10h] [ebp+Ch] BYREF va_start(va, a2);
 result = GetDebugOutput(); /*0xffc01871*/
 v3 = (int ( **)(int, int, char *))result; /*0xffc01876*/
 if ( result ) /*0xffc0187a*/
 {
 result = GetBootModeFromCMOS(); /*0xffc0187c*/
 if ( (result & a1) != 0 ) /*0xffc01887*/
 return (*v3)(a1, a2, (char *)va); /*0xffc01893*/
 }
 return result; /*0xffc01898*/
}

int DebugAssert(
 int e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
 int n48,
 int PeiServices____((void__)_0))
{
 int result; // eax result = GetDebugOutput(); /*0xffc018a0*/
 if ( result ) /*0xffc018a7*/
 return (*(int ( **)(int, int, int))(result + 4))( /*0xffc018af*/
 e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
 n48,
 PeiServices____((void__)_0));
 return result; /*0xffc018b5*/
}

char *CopyMemS(char *dst, char *src, unsigned int count)
{
 int DebugOutput; // eax int ErrorLevel; // eax if ( count - 1 > -1 - (int)dst ) /*0xffc018ce*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc018d0*/
 if ( DebugOutput ) /*0xffc018d7*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc018e5*/
 "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
 56,
 "(Length - 1) <= (0xFFFFFFFF - (UINTN)DestinationBuffer)");
 }
 if ( count - 1 > -1 - (int)src ) /*0xffc018ef*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc018f1*/
 if ( ErrorLevel ) /*0xffc018f8*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc01906*/
 "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
 57,
 "(Length - 1) <= (0xFFFFFFFF - (UINTN)SourceBuffer)");
 }
 if ( dst == src ) /*0xffc0190e*/
 return dst; /*0xffc01910*/
 else return CopyMem(dst, src, count); /*0xffc0191a*/
}

void *ZeroMemS(int buf, unsigned int count)
{
 int DebugOutput; // eax int ErrorLevel; // eax if ( !count ) /*0xffc0192f*/
 return (void *)buf; /*0xffc01931*/
 if ( !buf ) /*0xffc0193d*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc0193f*/
 if ( DebugOutput ) /*0xffc01946*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01950*/
 "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
 53,
 "Buffer != ((void *) 0)");
 }
 if ( count > -buf ) /*0xffc0195c*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc0195e*/
 if ( ErrorLevel ) /*0xffc01965*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc0196f*/
 "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
 54,
 "Length <= (0xFFFFFFFF - (UINTN)Buffer + 1)");
 }
 return ZeroMem((void *)buf, count); /*0xffc0197f*/
}

int GetHobList()
{
 int PeiServices; // eax int Status; // eax int DebugOutput; // eax int ErrorLevel; // eax int Result; // [esp+4h] [ebp-4h] BYREF PeiServices = GetPeiServices(); /*0xffc01987*/
 Status = (*(int ( **)(int, int *))(*(_DWORD *)PeiServices + 48))(PeiServices, &Result); /*0xffc01993*/
 if ( Status < 0 ) /*0xffc0199f*/
 {
 DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffc019ac*/
 DebugOutput = GetDebugOutput(); /*0xffc019b4*/
 if ( DebugOutput ) /*0xffc019bb*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc019c5*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 50,
 "!EFI_ERROR (Status)");
 }
 if ( !Result ) /*0xffc019cf*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc019d1*/
 if ( ErrorLevel ) /*0xffc019d8*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc019e2*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 51,
 "HobList != ((void *) 0)");
 }
 return Result; /*0xffc019eb*/
}

_WORD *GetNextHobByType(__int16 n5, _WORD *j)
{
 _WORD *j_1; // esi int DebugOutput; // eax j_1 = j; /*0xffc019f1*/
 if ( !j ) /*0xffc019f9*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc019fb*/
 if ( DebugOutput ) /*0xffc01a02*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01a10*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 82,
 "HobStart != ((void *) 0)");
 }
 while ( 1 ) /*0xffc01a28*/
 {
 if ( *j_1 == 0xFFFF ) /*0xffc01a2e*/
 return 0; /*0xffc01a34*/
 if ( *j_1 == n5 ) /*0xffc01a20*/
 break; /*0xffc01a20*/
 j_1 = (_WORD *)((char *)j_1 + (unsigned __int16)j_1[1]); /*0xffc01a26*/
 }
 return j_1; /*0xffc01a32*/
}

_WORD *GetNextGuidHob(int p_MarkerGuid, _WORD *j)
{
 _WORD *NextHobByType; // eax _WORD *NextHobByType_1; // esi while ( 1 ) /*0xffc01a57*/
 {
 NextHobByType = GetNextHobByType(4, j); /*0xffc01a57*/
 NextHobByType_1 = NextHobByType; /*0xffc01a5c*/
 if ( !NextHobByType || CompareGuid(p_MarkerGuid, (int)(NextHobByType + 4)) ) /*0xffc01a45*/
 break; /*0xffc01a45*/
 j = (_WORD *)((char *)NextHobByType_1 + (unsigned __int16)NextHobByType_1[1]); /*0xffc01a52*/
 }
 return NextHobByType_1; /*0xffc01a62*/
}

int InternalBuildHob(int n4, int n24)
{
 int PeiServices; // eax int DebugOutput; // eax int Result; // [esp+Ch] [ebp-4h] BYREF PeiServices = GetPeiServices(); /*0xffc01a73*/
 if ( (*(int ( **)(int, int, int, int *))(*(_DWORD *)PeiServices + 52))(PeiServices, n4, n24, &Result) < 0 ) /*0xffc01a8c*/
 Result = 0; /*0xffc01a8e*/
 if ( !Result ) /*0xffc01a96*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc01a98*/
 if ( DebugOutput ) /*0xffc01a9f*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01ab0*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 250,
 "Hob != ((void *) 0)");
 }
 return Result; /*0xffc01a87*/
}

int BuildGuidHob(int p_MarkerGuid, unsigned int n0xFFE0)
{
 int DebugOutput; // eax int ErrorLevel; // eax int result; // eax int Result; // esi if ( !p_MarkerGuid ) /*0xffc01acb*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc01acd*/
 if ( DebugOutput ) /*0xffc01ad4*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01ae1*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 416,
 "Guid != ((void *) 0)");
 }
 if ( n0xFFE0 > 0xFFE0 ) /*0xffc01aed*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc01aef*/
 if ( ErrorLevel ) /*0xffc01af6*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc01b03*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 421,
 "DataLength <= (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE))");
 }
 result = InternalBuildHob(4, n0xFFE0 + 24); /*0xffc01b0f*/
 Result = result; /*0xffc01b14*/
 if ( result ) /*0xffc01b18*/
 {
 CopyGuid((_DWORD *)(result + 8), p_MarkerGuid); /*0xffc01b1f*/
 return Result + 24; /*0xffc01b24*/
 }
 return result; /*0xffc01b27*/
}

char CheckFvAlignment(unsigned int a1, int a2, int a3)
{
 int v3; // ecx unsigned int n8; // esi v3 = *(_DWORD *)(a1 + 44); /*0xffc01b31*/
 if ( v3 < 0 ) /*0xffc01b36*/
 return 1; /*0xffc01b36*/
 n8 = 1 << (BYTE2(v3) & 0x1F); /*0xffc01b41*/
 if ( n8 < 8 ) /*0xffc01b46*/
 n8 = 8; /*0xffc01b4a*/
 if ( !(a1 % n8) ) /*0xffc01b4f*/
 return 1; /*0xffc01b79*/
 DebugPrint(0x80000000, (int)"Unaligned FvImage found at 0x%lx:0x%lx, the required alignment is 0x%x\n", a1, a2, a3); /*0xffc01b6d*/
 return 0; /*0xffc01b7b*/
}

int BuildFvHob(unsigned int a1, int a2, int a3, int a4)
{
 int result; // eax if ( CheckFvAlignment(a1, a2, a3) ) /*0xffc01b97*/
 {
 result = InternalBuildHob(5, 24); /*0xffc01bc9*/
 if ( result ) /*0xffc01bd0*/
 {
 *(_DWORD *)(result + 8) = a1; /*0xffc01bd2*/
 *(_DWORD *)(result + 12) = a2; /*0xffc01bd5*/
 *(_DWORD *)(result + 16) = a3; /*0xffc01bd8*/
 *(_DWORD *)(result + 20) = a4; /*0xffc01bdb*/
 }
 }
 else
 {
 result = GetDebugOutput(); /*0xffc01ba3*/
 if ( result ) /*0xffc01baa*/
 return (*(int ( **)(const char *, int, const char *))(result + 4))( /*0xffc01bbb*/
 "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
 556,
 "((BOOLEAN)(0==1))");
 }
 return result; /*0xffc01bde*/
}

void *PerformanceInit(int *PeiPerformanceLog, int *PeiPerformanceIdArray)
{
 int DebugOutputPtr; // eax int DebugOutput; // eax _WORD *HobList; // eax _WORD *PerfHob; // eax _WORD *HobList2; // eax _WORD *NextGuidHob; // edi int DebugPtr2; // eax void *Result; // eax int PerfLogBuffer; // eax int buf; // eax if ( !PeiPerformanceLog ) /*0xffc01bf4*/
 {
 DebugOutputPtr = GetDebugOutput(); /*0xffc01bf6*/
 if ( DebugOutputPtr ) /*0xffc01bfd*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc01c07*/
 "e:\\hs\\MdeModulePkg\\Library\\PeiPerformanceLib\\PeiPerformanceLib.c",
 57,
 "PeiPerformanceLog != ((void *) 0)");
 }
 if ( !PeiPerformanceIdArray ) /*0xffc01c0f*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc01c11*/
 if ( DebugOutput ) /*0xffc01c18*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc01c22*/
 "e:\\hs\\MdeModulePkg\\Library\\PeiPerformanceLib\\PeiPerformanceLib.c",
 58,
 "PeiPerformanceIdArray != ((void *) 0)");
 }
 HobList = (_WORD *)GetHobList(); /*0xffc01c28*/
 PerfHob = GetNextGuidHob((int)&unk_FFC032BC, HobList); /*0xffc01c36*/
 if ( PerfHob ) /*0xffc01c3d*/
 {
 *PeiPerformanceLog = (int)(PerfHob + 12); /*0xffc01c42*/
 HobList2 = (_WORD *)GetHobList(); /*0xffc01c44*/
 NextGuidHob = GetNextGuidHob((int)&unk_FFC0325C, HobList2); /*0xffc01c55*/
 if ( !NextGuidHob ) /*0xffc01c59*/
 {
 DebugPtr2 = GetDebugOutput(); /*0xffc01c5b*/
 if ( DebugPtr2 ) /*0xffc01c62*/
 (*(void ( **)(const char *, int, const char *))(DebugPtr2 + 4))( /*0xffc01c6c*/
 "e:\\hs\\MdeModulePkg\\Library\\PeiPerformanceLib\\PeiPerformanceLib.c",
 72,
 "GuidHob != ((void *) 0)");
 }
 Result = NextGuidHob + 12; /*0xffc01c72*/
 }
 else
 {
 PerfLogBuffer = BuildGuidHob((int)&unk_FFC032BC, 0x9C48u); /*0xffc01c80*/
 *PeiPerformanceLog = PerfLogBuffer; /*0xffc01c87*/
 *PeiPerformanceLog = (int)ZeroMemS(PerfLogBuffer, 0x9C48u); /*0xffc01c90*/
 buf = BuildGuidHob((int)&unk_FFC0325C, 0xFA0u); /*0xffc01c9e*/
 *PeiPerformanceIdArray = buf; /*0xffc01ca5*/
 Result = ZeroMemS(buf, 0xFA0u); /*0xffc01ca9*/
 }
 *PeiPerformanceIdArray = (int)Result; /*0xffc01caf*/
 return Result; /*0xffc01cae*/
}

int __thiscall PerformanceGetFreeEntry(unsigned int *this, int a2, _BYTE *a3)
{
 _BYTE *v3; // edx unsigned int v5; // eax int Index; // esi int Result; // ebx int v8; // ebp unsigned int v10; // [esp+8h] [ebp-4h]

 v3 = a3; /*0xffc01cb7*/
 if ( !a3 ) /*0xffc01cc1*/
 {
 v3 = byte_FFC02C60; /*0xffc01cc3*/
 a3 = byte_FFC02C60; /*0xffc01cc8*/
 }
 v5 = *this; /*0xffc01ccc*/
 Index = 0; /*0xffc01cce*/
 v10 = *this; /*0xffc01cd0*/
 if ( *this ) /*0xffc01ccc*/
 {
 while ( 1 ) /*0xffc01cde*/
 {
 Result = v5 - Index - 1; /*0xffc01cde*/
 v8 = 40 *Result; /*0xffc01cdf*/
 if ( !*((_QWORD *)this + 5 *Result + 5) /*0xffc01d13*/
 && !*(_QWORD *)((char *)this + v8 + 8)
 && !AsciiStrCmp((_BYTE *)this + v8 + 16, v3, 7u)
 && !AsciiStrCmp((_BYTE *)this + v8 + 24, byte_FFC02C60, 7u) )
 {
 break; /*0xffc01d13*/
 }
 v5 = v10; /*0xffc01d1d*/
 if ( ++Index >= v10 ) /*0xffc01d24*/
 return Index; /*0xffc01d24*/
 v3 = a3; /*0xffc01d26*/
 }
 return Result; /*0xffc01d2c*/
 }
 return Index; /*0xffc01d30*/
}

int PerformanceStart(int PerfToken, char *PRL_AM)
{
 _DWORD *v3; // esi int Ptr; // ebx int Index; // edi int v7; // eax _DWORD *v8; // [esp+14h] [ebp-8h] BYREF int v9; // [esp+18h] [ebp-4h] BYREF PerformanceInit((int *)&v8, &v9); /*0xffc01d47*/
 v3 = v8; /*0xffc01d4c*/
 Ptr = *v8; /*0xffc01d50*/
 if ( *v8 < 0x3E8u ) /*0xffc01d58*/
 {
 Index = 10 *Ptr; /*0xffc01d72*/
 *v8 = Ptr + 1; /*0xffc01d7a*/
 v3[Index + 2] = 0; /*0xffc01d7c*/
 v3[Index + 3] = 0; /*0xffc01d80*/
 if ( PRL_AM ) /*0xffc01d86*/
 AsciiStrCpyS(PRL_AM); /*0xffc01d8f*/
 v7 = v9; /*0xffc01d98*/
 v3[Index + 10] = 0; /*0xffc01d9c*/
 v3[Index + 11] = 0; /*0xffc01da0*/
 *(_DWORD *)(v7 + 4 *Ptr) = 0; /*0xffc01da4*/
 *(_QWORD *)&v3[Index + 8] = __rdtsc(); /*0xffc01da9*/
 return 0; /*0xffc01dad*/
 }
 else
 {
 DebugPrint(0x80000000, (int)"PEI performance log array out of resources\n"); /*0xffc01d64*/
 return -2147483639; /*0xffc01d6b*/
 }
}

int PerformanceEnd(int a1, _BYTE *a2)
{
 unsigned __int64 v3; // rax unsigned int v4; // ebx unsigned int v5; // edi unsigned int *v6; // esi int v7; // ecx unsigned int FreeEntry; // eax int Index; // eax _BYTE *v11; // [esp-Ch] [ebp-20h]
 int v12; // [esp+Ch] [ebp-8h] BYREF unsigned int *v13; // [esp+10h] [ebp-4h] BYREF v3 = __rdtsc(); /*0xffc01dc5*/
 v4 = HIDWORD(v3); /*0xffc01dc7*/
 v5 = v3; /*0xffc01dcf*/
 PerformanceInit((int *)&v13, &v12); /*0xffc01dd1*/
 v11 = a2; /*0xffc01dd8*/
 v6 = v13; /*0xffc01dd9*/
 FreeEntry = PerformanceGetFreeEntry(v13, v7, v11); /*0xffc01ddf*/
 if ( FreeEntry >= *v6 ) /*0xffc01de9*/
 return -2147483634; /*0xffc01deb*/
 Index = 10 * (FreeEntry + 1); /*0xffc01df3*/
 v6[Index] = v5; /*0xffc01df6*/
 v6[Index + 1] = v4; /*0xffc01df9*/
 return 0; /*0xffc01dff*/
}

_DWORD *FvCacheInit()
{
 int PeiServices; // eax int HobList; // esi int PeiServices2; // eax _DWORD *RomLayoutEntry; // esi _DWORD *HobHeader; // eax unsigned int SrcOffset; // ecx unsigned int EntrySize; // ebx char *DstPtr; // edi int OffsetAdjust; // ebp char *SrcPtr; // [esp+8h] [ebp-Ch]
 int HobList_1; // [esp+Ch] [ebp-8h] BYREF int RomLayoutHob; // [esp+10h] [ebp-4h] BYREF HobList_1 = 0; /*0xffc01e0d*/
 RomLayoutHob = 0; /*0xffc01e11*/
 PeiServices = GetPeiServices(); /*0xffc01e15*/
 if ( (*(int ( **)(int, _DWORD, int *))(*(_DWORD *)PeiServices + 56))(PeiServices, 0, &HobList_1) < 0 ) /*0xffc01e2b*/
 return 0; /*0xffc01e2b*/
 HobList = HobList_1; /*0xffc01e31*/
 PeiServices2 = GetPeiServices(); /*0xffc01e35*/
 if ( (*(int ( **)(int *, int, int *))(*(_DWORD *)PeiServices2 + 104))(&dword_FFC0326C, HobList, &RomLayoutHob) < 0 ) /*0xffc01e4f*/
 return 0; /*0xffc01e4f*/
 RomLayoutEntry = (_DWORD *)(RomLayoutHob + 44); /*0xffc01e59*/
 if ( *(_DWORD *)(RomLayoutHob + 44) != 1280134994 ) /*0xffc01e62*/
 return 0; /*0xffc01efd*/
 HobHeader = (_DWORD *)BuildGuidHob((int)&unk_FFC0327C, 48 * *(_DWORD *)(RomLayoutHob + 56) + 16); /*0xffc01e77*/
 if ( HobHeader ) /*0xffc01e80*/
 {
 *HobHeader = RomLayoutEntry[1]; /*0xffc01e85*/
 HobHeader[1] = RomLayoutEntry[2]; /*0xffc01e8a*/
 SrcOffset = (unsigned int)(RomLayoutEntry + 4); /*0xffc01e8d*/
 HobHeader[2] = 48; /*0xffc01e90*/
 HobHeader[3] = 0; /*0xffc01e97*/
 EntrySize = RomLayoutEntry[2]; /*0xffc01e9d*/
 SrcPtr = (char *)(RomLayoutEntry + 4); /*0xffc01ea4*/
 DstPtr = (char *)(HobHeader + 4); /*0xffc01ea8*/
 if ( RomLayoutEntry + 4 < (_DWORD *)((char *)RomLayoutEntry + EntrySize *RomLayoutEntry[3] + 16) ) /*0xffc01eb1*/
 {
 OffsetAdjust = 16 - (_DWORD)HobHeader; /*0xffc01eb3*/
 do /*0xffc01ef5*/
 {
 if ( EntrySize ) /*0xffc01eb7*/
 {
 CopyMemS(DstPtr + 8, SrcPtr, EntrySize); /*0xffc01ec1*/
 SrcOffset = (unsigned int)SrcPtr; /*0xffc01ec7*/
 }
 *((_DWORD *)DstPtr + 1) = 0; /*0xffc01ecb*/
 *(_DWORD *)DstPtr = &DstPtr[OffsetAdjust + 8]; /*0xffc01ed4*/
 DstPtr += 48; /*0xffc01ed6*/
 EntrySize = RomLayoutEntry[2]; /*0xffc01ed9*/
 SrcPtr = (char *)(EntrySize + SrcOffset); /*0xffc01ede*/
 SrcOffset += EntrySize; /*0xffc01ef1*/
 }
 while ( SrcOffset < (unsigned int)RomLayoutEntry + EntrySize *RomLayoutEntry[3] + 16 ); /*0xffc01ef5*/
 }
 }
 return RomLayoutEntry; /*0xffc01eff*/
}

int __usercall FvCacheGetEntryInfo@<eax>(_DWORD *a1@<edx>, _DWORD *a2)
{
 _WORD *HobList; // eax _WORD *NextGuidHob; // esi _WORD *j; // eax HobList = (_WORD *)GetHobList(); /*0xffc01f0b*/
 NextGuidHob = GetNextGuidHob((int)&MarkerGuid_0, HobList); /*0xffc01f1e*/
 if ( !NextGuidHob ) /*0xffc01f22*/
 {
 FvCacheInit(); /*0xffc01f24*/
 j = (_WORD *)GetHobList(); /*0xffc01f29*/
 NextGuidHob = GetNextGuidHob((int)&MarkerGuid_0, j); /*0xffc01f37*/
 if ( !NextGuidHob ) /*0xffc01f3b*/
 return -2147483634; /*0xffc01f3d*/
 }
 if ( a1 ) /*0xffc01f46*/
 *a1 = *((_DWORD *)NextGuidHob + 7); /*0xffc01f4b*/
 if ( a2 ) /*0xffc01f53*/
 *a2 = *((_DWORD *)NextGuidHob + 7) /*0xffc01f65*/
 * (((unsigned int)(unsigned __int16)NextGuidHob[1] - 40)
 / *((_DWORD *)NextGuidHob + 8));
 return 0; /*0xffc01f69*/
}

unsigned int FvCacheGetFirst()
{
 _WORD *HobList; // eax _WORD *NextGuidHob; // edx _WORD *j; // eax HobList = (_WORD *)GetHobList(); /*0xffc01f6f*/
 NextGuidHob = GetNextGuidHob((int)&MarkerGuid_0, HobList); /*0xffc01f82*/
 if ( !NextGuidHob ) /*0xffc01f86*/
 {
 FvCacheInit(); /*0xffc01f88*/
 j = (_WORD *)GetHobList(); /*0xffc01f8d*/
 NextGuidHob = GetNextGuidHob((int)&MarkerGuid_0, j); /*0xffc01f9b*/
 }
 return NextGuidHob != 0 ? (unsigned int)(NextGuidHob + 24) : 0;
}

unsigned int __thiscall FvCacheGetNext(char *i)
{
 char *v1; // esi char *v2; // edi unsigned int Result; // esi if ( i /*0xffc01fdc*/
 && (v1 = i - 8, v2 = &v1[-*(_DWORD *)v1], CompareGuid((int)(v2 + 8), (int)&MarkerGuid_0))
 && (Result = (unsigned int)&v1[*((_DWORD *)v2 + 8)], (unsigned int)(v2 + 40) <= Result)
 && (unsigned int)&v2[*((unsigned __int16 *)v2 + 1)] > Result )
 {
 return Result + 8; /*0xffc01fde*/
 }
 else
 {
 return 0; /*0xffc01fe3*/
 }
}

int FindRomLayoutMarker(
 _DWORD *OutRomLayoutData,
 _DWORD *OutSrcSize,
 _DWORD *OutEntryCount,
 _DWORD *p_TotalSize)
{
 _DWORD *FvFormat_2; // ecx _DWORD *FvFormat_1; // edi _DWORD *FvFormat; // esi int DebugOutputPtr; // eax int MarkerGuid; // ebp FvFormat_1 = FvFormat_2; /*0xffc01fee*/
 if ( !FvFormat_2 || !OutRomLayoutData ) /*0xffc01ffe*/
 return -2147483646; /*0xffc020a9*/
 FvFormat = FvFormat_2 + 4194289; /*0xffc02004*/
 if ( FvFormat_2 + 4194289 != (_DWORD *)((unsigned int)(FvFormat_2 + 4194289) & 0xFFFFFFFC) ) /*0xffc02011*/
 {
 DebugOutputPtr = GetDebugOutput(); /*0xffc02013*/
 if ( DebugOutputPtr ) /*0xffc0201a*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc0202b*/
 "e:\\hs\\AmiModulePkg\\Library\\AmiRomLayout\\PeiAmiRomLayoutLib.c",
 312,
 "(UINTN)SearchPointer == ((UINTN)SearchPointer & (~0x03))");
 }
 MarkerGuid = ::MarkerGuid; /*0xffc02031*/
 while ( 1 ) /*0xffc0206a*/
 {
 if ( FvFormat == FvFormat_1 ) /*0xffc0206c*/
 return -2147483634; /*0xffc02073*/
 if ( *FvFormat == MarkerGuid /*0xffc02065*/
 && CompareGuid((int)&::MarkerGuid, (int)FvFormat)
 && CompareGuid((int)&MarkerGuid_0, (int)(FvFormat + 7))
 && FvFormat[11] == 1280134994 )
 {
 break; /*0xffc02065*/
 }
 --FvFormat; /*0xffc02067*/
 }
 if ( OutSrcSize ) /*0xffc0207b*/
 *OutSrcSize = FvFormat[12]; /*0xffc02080*/
 if ( OutEntryCount ) /*0xffc02088*/
 *OutEntryCount = FvFormat[13]; /*0xffc0208d*/
 if ( p_TotalSize ) /*0xffc02095*/
 *p_TotalSize = FvFormat[13] *FvFormat[14]; /*0xffc0209e*/
 *OutRomLayoutData = FvFormat + 15; /*0xffc020a3*/
 return 0; /*0xffc020ae*/
}

int __thiscall ProcessFvHob(int *this)
{
 int Result; // ebp int *v3; // ebx __int64 Unaligned64; // rax int v6; // edi int v7; // esi int v8; // eax int Table; // [esp-8h] [ebp-1Ch]

 Result = -2147483646; /*0xffc020bb*/
 if ( this ) /*0xffc020c2*/
 {
 v3 = this + 4; /*0xffc020c4*/
 if ( (*(this + 5) & *(this + 4)) == 0xFFFFFFFF ) /*0xffc020cf*/
 return -2147483631; /*0xffc020d4*/
 Result = -2147483638; /*0xffc020d8*/
 if ( *(_DWORD *)(ReadUnaligned64(this + 4) + 40) == 1213613663 ) /*0xffc020e9*/
 {
 Result = 0; /*0xffc020eb*/
 Table = *(this + 7); /*0xffc020f0*/
 Unaligned64 = ReadUnaligned64(this + 4); /*0xffc020f3*/
 BuildFvHob(Unaligned64, SHIDWORD(Unaligned64), Table, 0); /*0xffc020fa*/
 v6 = *(this + 7); /*0xffc020ff*/
 v7 = ReadUnaligned64(v3); /*0xffc0210b*/
 v8 = ReadUnaligned64(v3); /*0xffc0210d*/
 InstallFvInfoPpi(v8 + 16, v7, v6); /*0xffc0211a*/
 }
 }
 return Result; /*0xffc02124*/
}

int GetBootModeFromCMOS()
{
 unsigned __int8 v0; // al char Result; // al char n3_1; // cl v0 = __inbyte(0x70u); /*0xffc02160*/
 __outbyte(0x70u, v0 & 0x80 | 0x4A); /*0xffc02165*/
 Result = __inbyte(0x71u); /*0xffc0216c*/
 n3_1 = Result; /*0xffc0216d*/
 if ( (unsigned __int8)Result <= 3u ) /*0xffc02172*/
 {
LABEL_4:
 if ( !n3_1 ) /*0xffc0218d*/
 return 0; /*0xffc0218d*/
 goto LABEL_5; /*0xffc0218d*/
 }
 n3_1 = Result; /*0xffc02174*/
 if ( !Result ) /*0xffc0217c*/
 {
 n3_1 = MEMORY[0xFDAF0490] & 2 | 1; /*0xffc02188*/
 goto LABEL_4; /*0xffc02188*/
 }
LABEL_5:
 if ( n3_1 != -1 )
 return n3_1 != 1 ? -2147483578 : -2147483644;
 return 0; /*0xffc021a5*/
}

unsigned int __thiscall AsciiStrLen(_BYTE *this)
{
 _BYTE *this_1; // esi int DebugOutput; // eax unsigned int n0xF4240; // edi int ErrorLevel; // eax this_1 = this; /*0xffc021ab*/
 if ( !this ) /*0xffc021b5*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc021b7*/
 if ( DebugOutput ) /*0xffc021be*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc021cb*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
 1082,
 "String != ((void *) 0)");
 }
 n0xF4240 = 0; /*0xffc021d1*/
 while ( *this_1 ) /*0xffc021fc*/
 {
 if ( n0xF4240 >= 0xF4240 ) /*0xffc021db*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc021dd*/
 if ( ErrorLevel ) /*0xffc021e4*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc021f1*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
 1090,
 "Length < _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength");
 }
 ++this_1; /*0xffc021f7*/
 ++n0xF4240; /*0xffc021f8*/
 }
 return n0xF4240; /*0xffc02200*/
}

int AsciiStrCmp(_BYTE *a1, _BYTE *a2, unsigned int n7)
{
 _BYTE *v4; // esi int DebugOutput; // eax int ErrorLevel; // eax unsigned int n7_1; // edi int ErrorLevel; // eax v4 = a1; /*0xffc0220a*/
 if ( AsciiStrLen(a1) == -1 ) /*0xffc02219*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc0221b*/
 if ( DebugOutput ) /*0xffc02222*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc0222f*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
 1320,
 "AsciiStrSize (FirstString)");
 }
 if ( AsciiStrLen(a2) == -1 ) /*0xffc0223f*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc02241*/
 if ( ErrorLevel ) /*0xffc02248*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc02255*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
 1321,
 "AsciiStrSize (SecondString)");
 }
 n7_1 = n7; /*0xffc0225b*/
 if ( n7 > 0xF4240 ) /*0xffc02265*/
 {
 ErrorLevel = GetDebugOutput(); /*0xffc02267*/
 if ( ErrorLevel ) /*0xffc0226e*/
 (*(void ( **)(const char *, int, const char *))(ErrorLevel + 4))( /*0xffc0227b*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
 1324,
 "Length <= _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength");
 }
 while ( *v4 && *a2 && *v4 == *a2 && n7_1 > 1 ) /*0xffc02290*/
 {
 ++v4; /*0xffc02292*/
 ++a2; /*0xffc02293*/
 --n7_1; /*0xffc02294*/
 }
 return (char)*v4 - (char)*a2; /*0xffc022a1*/
}

char IsOverlap(unsigned int PRL_AM, int a2)
{
 unsigned int PRL_AM_1; // ecx if ( PRL_AM > PRL_AM_1 ) /*0xffc022ae*/
 goto LABEL_4; /*0xffc022ae*/
 if ( PRL_AM_1 < PRL_AM + a2 ) /*0xffc022b8*/
 return 1; /*0xffc022c7*/
 if ( PRL_AM >= PRL_AM_1 ) /*0xffc022bc*/
 {
LABEL_4:
 if ( PRL_AM < PRL_AM_1 + 8 ) /*0xffc022c3*/
 return 1; /*0xffc022c3*/
 }
 return 0; /*0xffc022c7*/
}

unsigned int __thiscall AsciiStrnLenS(_BYTE *this)
{
 unsigned int Index; // eax Index = 0; /*0xffc022cb*/
 if ( this && *this ) /*0xffc022d1*/
 {
 while ( Index < 7 ) /*0xffc022d8*/
 {
 if ( !*(this + ++Index) ) /*0xffc022db*/
 return Index; /*0xffc022df*/
 }
 return 8; /*0xffc022e4*/
 }
 return Index; /*0xffc022e1*/
}

int AsciiStrCpyS(char *Source)
{
 _BYTE *Destination; // ecx _BYTE *Destination_1; // esi int DebugDst; // eax int DebugSrc; // eax unsigned int MaxCount; // ebx int DebugOutputPtr; // eax char Char; // al char *Delta; // edi Destination_1 = Destination; /*0xffc022eb*/
 if ( Destination ) /*0xffc022ef*/
 {
 if ( Source ) /*0xffc0231f*/
 {
 MaxCount = AsciiStrnLenS(Source); /*0xffc0234e*/
 if ( MaxCount > 7 ) /*0xffc02353*/
 MaxCount = 7; /*0xffc02357*/
 if ( IsOverlap((unsigned int)Source, MaxCount + 1) ) /*0xffc0235f*/
 {
 DebugOutputPtr = GetDebugOutput(); /*0xffc0236e*/
 if ( DebugOutputPtr ) /*0xffc02375*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc02386*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\SafeString.c",
 1930,
 "InternalSafeStringNoAsciiStrOverlap (Destination, DestMax, (CHAR8 *)Source, SourceLen + 1)");
 return -2147483633; /*0xffc02393*/
 }
 else
 {
 Char = *Source; /*0xffc0239a*/
 if ( *Source ) /*0xffc0239a*/
 {
 Delta = (char *)(Source - Destination_1); /*0xffc023a0*/
 do /*0xffc023af*/
 {
 if ( !MaxCount ) /*0xffc023a4*/
 break; /*0xffc023a4*/
 *Destination_1++ = Char; /*0xffc023a6*/
 --MaxCount; /*0xffc023a9*/
 Char = Destination_1[(_DWORD)Delta]; /*0xffc023aa*/
 }
 while ( Char ); /*0xffc023af*/
 }
 *Destination_1 = 0; /*0xffc023b1*/
 return 0; /*0xffc023b4*/
 }
 }
 else
 {
 DebugSrc = GetDebugOutput(); /*0xffc02321*/
 if ( DebugSrc ) /*0xffc02328*/
 (*(void ( **)(const char *, int, const char *))(DebugSrc + 4))( /*0xffc02339*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\SafeString.c",
 1901,
 "(Source != ((void *) 0))");
 return -2147483646; /*0xffc0233f*/
 }
 }
 else
 {
 DebugDst = GetDebugOutput(); /*0xffc022f1*/
 if ( DebugDst ) /*0xffc022f8*/
 (*(void ( **)(const char *, int, const char *))(DebugDst + 4))( /*0xffc02309*/
 "e:\\hs\\MdePkg\\Library\\BaseLib\\SafeString.c",
 1900,
 "(Destination != ((void *) 0))");
 return -2147483646; /*0xffc0230f*/
 }
}

int GetPeiServices()
{
 int Result; // esi _BYTE v2[2]; // [esp+4h] [ebp-8h] BYREF int v3; // [esp+6h] [ebp-6h]

 ReadIdtr(v2); /*0xffc023e3*/
 Result = *(_DWORD *)(v3 - 4); /*0xffc023eb*/
 if ( !Result ) /*0xffc023f0*/
 DebugAssert( /*0xffc023ff*/
 (int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
 48,
 (int)"PeiServices != ((void *) 0)");
 return Result; /*0xffc02407*/
}

int PeiFreePages(int AllocatedAddr, int AlignmentPages)
{
 int v2; // ecx int v3; // esi int PeiServices; // eax v3 = v2; /*0xffc0240d*/
 PeiServices = GetPeiServices(); /*0xffc0240f*/
 return (*(int ( **)(int, int, int, int))(*(_DWORD *)PeiServices + 132))( /*0xffc02429*/
 PeiServices,
 AllocatedAddr,
 AlignmentPages,
 v3);
}

int __usercall InstallFvInfoPpi@<eax>(int FvFormat@<edx>, int FvInfo, int FvInfoSize)
{
 int FvInfoPpi; // eax _DWORD *FvInfoPpi_1; // esi int DebugOutputPtr; // eax int DebugOutput; // eax _DWORD *Pages; // edi int DebugPtr2; // eax int PeiServices; // eax int Status; // eax FvInfoPpi = InternalAllocatePages((void *)0x20); /*0xffc02434*/
 FvInfoPpi_1 = (_DWORD *)FvInfoPpi; /*0xffc02439*/
 if ( !FvInfoPpi || (FvInfoPpi_1 = ZeroMemS(FvInfoPpi, 0x20u)) == 0 ) /*0xffc02452*/
 {
 DebugOutputPtr = GetDebugOutput(); /*0xffc02454*/
 if ( DebugOutputPtr ) /*0xffc0245b*/
 (*(void ( **)(const char *, int, const char *))(DebugOutputPtr + 4))( /*0xffc02468*/
 "e:\\hs\\MdePkg\\Library\\PeiServicesLib\\PeiServicesLib.c",
 653,
 "FvInfoPpi != ((void *) 0)");
 }
 if ( FvFormat ) /*0xffc02476*/
 {
 CopyGuid(FvInfoPpi_1, FvFormat); /*0xffc0247a*/
 }
 else
 {
 CopyGuid(FvInfoPpi_1, (int)&FvFormat_); /*0xffc02488*/
 if ( !CompareGuid(FvInfo + 16, (int)&FvFormat_) ) /*0xffc02492*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc0249b*/
 if ( DebugOutput ) /*0xffc024a2*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc024af*/
 "e:\\hs\\MdePkg\\Library\\PeiServicesLib\\PeiServicesLib.c",
 678,
 "CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid), &gEfiFirmwareFileSystem2Guid)");
 }
 }
 FvInfoPpi_1[4] = FvInfo; /*0xffc024bc*/
 FvInfoPpi_1[5] = FvInfoSize; /*0xffc024bf*/
 Pages = (_DWORD *)InternalAllocatePages((void *)0xC); /*0xffc024c7*/
 if ( !Pages ) /*0xffc024cb*/
 {
 DebugPtr2 = GetDebugOutput(); /*0xffc024cd*/
 if ( DebugPtr2 ) /*0xffc024d4*/
 (*(void ( **)(const char *, int, const char *))(DebugPtr2 + 4))( /*0xffc024e1*/
 "e:\\hs\\MdePkg\\Library\\PeiServicesLib\\PeiServicesLib.c",
 694,
 "FvInfoPpiDescriptor != ((void *) 0)");
 }
 Pages[1] = &unk_FFC032CC; /*0xffc024e7*/
 *Pages = -2147483632; /*0xffc024ee*/
 Pages[2] = FvInfoPpi_1; /*0xffc024f4*/
 PeiServices = GetPeiServices(); /*0xffc024f7*/
 Status = (*(int ( **)(int, _DWORD *))(*(_DWORD *)PeiServices + 24))(PeiServices, Pages); /*0xffc02500*/
 if ( Status < 0 ) /*0xffc02507*/
 {
 DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffc02514*/
 Status = GetDebugOutput(); /*0xffc0251c*/
 if ( Status ) /*0xffc02523*/
 return (*(int ( **)(const char *, int, const char *))(Status + 4))( /*0xffc02530*/
 "e:\\hs\\MdePkg\\Library\\PeiServicesLib\\PeiServicesLib.c",
 700,
 "!EFI_ERROR (Status)");
 }
 return Status; /*0xffc02536*/
}

_DWORD *CopyGuid(_DWORD *buf, int FvFormat)
{
 __int64 Unaligned64; // rax __int64 Unaligned64_1; // rax Unaligned64 = ReadUnaligned64((void *)FvFormat); /*0xffc02543*/
 WriteUnaligned64(Unaligned64, SHIDWORD(Unaligned64)); /*0xffc0254c*/
 Unaligned64_1 = ReadUnaligned64((void *)(FvFormat + 8)); /*0xffc02554*/
 WriteUnaligned64(Unaligned64_1, SHIDWORD(Unaligned64_1)); /*0xffc0255e*/
 return buf; /*0xffc02568*/
}

bool CompareGuid(int p_MarkerGuid, int FvFormat)
{
 __int64 Unaligned64; // rax int Unaligned64_1; // ebp __int64 Unaligned64_3; // rax int Unaligned64_2; // edi __int64 Protocol; // kr00_8 __int64 v9; // rax int v11; // [esp+10h] [ebp-Ch]
 int v12; // [esp+14h] [ebp-8h]

 Unaligned64 = ReadUnaligned64((void *)p_MarkerGuid); /*0xffc02576*/
 v12 = HIDWORD(Unaligned64); /*0xffc0257d*/
 Unaligned64_1 = Unaligned64; /*0xffc02581*/
 Unaligned64_3 = ReadUnaligned64((void *)FvFormat); /*0xffc02583*/
 v11 = HIDWORD(Unaligned64_3); /*0xffc0258b*/
 Unaligned64_2 = Unaligned64_3; /*0xffc0258f*/
 Protocol = ReadUnaligned64((void *)(p_MarkerGuid + 8)); /*0xffc0259d*/
 v9 = ReadUnaligned64((void *)(FvFormat + 8)); /*0xffc0259f*/
 return Unaligned64_1 == Unaligned64_2 && v12 == v11 && Protocol == v9; /*0xffc025c2*/
}

void *__thiscall ReadIdtr(void *this)
{
 void *this_1; // eax if ( !this ) /*0xffc025d0*/
 DebugAssert((int)"e:\\hs\\MdePkg\\Library\\BaseLib\\X86ReadIdtr.c", 37, (int)"Idtr != ((void *) 0)"); /*0xffc025df*/
 this_1 = this; /*0xffc025e5*/
 __sidt(this); /*0xffc025e8*/
 return this_1; /*0xffc025ec*/
}

int __thiscall GetPcdToken(void *this)
{
 int ( **PcdDb)(int); // eax PcdDb = (int ( **)(int))GetPcdDb(this); /*0xffc025ed*/
 return PcdDb[4](5); /*0xffc025f8*/
}

int __thiscall SetIoPort80(void *this)
{
 int v1; // ebx int DebugOutput; // eax v1 = GetPcdToken(this) + 1024064; /*0xffc0212b*/
 if ( (v1 & 1) != 0 ) /*0xffc02130*/
 {
 DebugOutput = GetDebugOutput(); /*0xffc02132*/
 if ( DebugOutput ) /*0xffc02139*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc0214a*/
 "e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLib.c",
 183,
 "(Address & 1) == 0");
 }
 *(_WORD *)v1 = 1280; /*0xffc02155*/
 return 1280; /*0xffc02159*/
}

void *__thiscall GetPcdDb(void *this)
{
 int PeiServices; // eax int Status; // eax int DebugOutput; // eax void *this_1; // [esp+0h] [ebp-4h]

 this_1 = this; /*0xffc0260d*/
 PeiServices = GetPeiServices(); /*0xffc0260e*/
 Status = (*(int (__stdcall **)(int))(*(_DWORD *)PeiServices + 32))(PeiServices); /*0xffc02623*/
 if ( Status < 0 ) /*0xffc0262b*/
 {
 DebugPrint(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffc02638*/
 DebugOutput = GetDebugOutput(); /*0xffc02640*/
 if ( DebugOutput ) /*0xffc02647*/
 (*(void ( **)(const char *, int, const char *))(DebugOutput + 4))( /*0xffc02655*/
 "e:\\hs\\MdePkg\\Library\\PeiPcdLib\\PeiPcdLib.c",
 49,
 "!EFI_ERROR (Status)");
 }
 return this_1; /*0xffc02660*/
}