#include "Platform.h"

//
// Platform - UEFI Module (Regenerated from IDA)
// Total functions: 50
//

// Function: InternalZeroMem @ 0xffde7fd8 (0x20 bytes)
// Index: 1/50

void *__cdecl InternalZeroMem(void *buf, unsigned int this)
{
  memset(buf, 0, this); /*0xffde7fef*/
  return buf; /*0xffde7ff6*/
}


// Function: InternalCopyMem @ 0xffde7ff8 (0x3f bytes)
// Index: 2/50

char *__cdecl InternalCopyMem(char *dst, char *src, unsigned int n4102)
{
  unsigned int n4102_1; // edx
  char *dst_1; // edi
  char *src_1; // esi

  n4102_1 = n4102; /*0xffde8002*/
  if ( src < dst && &src[n4102 - 1] >= dst ) /*0xffde8010*/
  {
    src_1 = &src[n4102 - 1]; /*0xffde8024*/
    dst_1 = &dst[n4102 - 1]; /*0xffde8026*/
  }
  else
  {
    n4102_1 = n4102 & 3; /*0xffde8014*/
    qmemcpy(dst, src, 4 * (n4102 >> 2)); /*0xffde801d*/
    src_1 = &src[4 * (n4102 >> 2)]; /*0xffde801d*/
    dst_1 = &dst[4 * (n4102 >> 2)]; /*0xffde801d*/
  }
  qmemcpy(dst_1, src_1, n4102_1); /*0xffde802d*/
  return dst; /*0xffde8034*/
}


// Function: SetMem @ 0xffde8038 (0x15 bytes)
// Index: 3/50

void *__cdecl SetMem(void *buf, unsigned int count, char value)
{
  memset(buf, value, count); /*0xffde8045*/
  return buf; /*0xffde804b*/
}


// Function: SetMem32_Repeated @ 0xffde8058 (0x1f bytes)
// Index: 4/50

int __cdecl SetMem32_Repeated(int a1, int a2, int a3, int a4)
{
  do /*0xffde8071*/
  {
    *(_DWORD *)(a1 + 8 * a2 - 8) = a3; /*0xffde8069*/
    *(_DWORD *)(a1 + 8 * a2-- - 4) = a4; /*0xffde806d*/
  }
  while ( a2 ); /*0xffde8071*/
  return a1; /*0xffde8075*/
}


// Function: SetMem32 @ 0xffde8078 (0x15 bytes)
// Index: 5/50

void *__cdecl SetMem32(void *buf, unsigned int count, int value)
{
  memset32(buf, value, count); /*0xffde8085*/
  return buf; /*0xffde808b*/
}


// Function: _ModuleEntryPoint @ 0xffde808d (0x9 bytes)
// Index: 6/50

// (too small: 0x9 bytes)


// Function: ReadBoardIdFromIoPorts @ 0xffde8096 (0x8b bytes)
// Index: 7/50

int ReadBoardIdFromIoPorts()
{
  unsigned __int8 BoardId; // bl
  int IoDelayCount; // ecx
  int n40; // esi
  int IoDelayCount1; // esi
  int n40_1; // esi
  unsigned __int8 GpioData2; // al
  int IoDelayCount2; // esi
  unsigned __int8 GpioData3; // al

  BoardId = 0; /*0xffde809a*/
  __outbyte(0x2Eu, 0x5Au); /*0xffde80a4*/
  IoDelayCount = 40; /*0xffde80a7*/
  n40 = 40; /*0xffde80aa*/
  do /*0xffde80b4*/
  {
    __inbyte(0x61u); /*0xffde80b0*/
    --n40; /*0xffde80b1*/
  }
  while ( n40 ); /*0xffde80b4*/
  __outbyte(0x2Eu, 7u); /*0xffde80bb*/
  IoDelayCount1 = 40; /*0xffde80bc*/
  do /*0xffde80c5*/
  {
    __inbyte(0x61u); /*0xffde80c1*/
    --IoDelayCount1; /*0xffde80c2*/
  }
  while ( IoDelayCount1 ); /*0xffde80c5*/
  __outbyte(0x2Fu, 2u); /*0xffde80cf*/
  n40_1 = 40; /*0xffde80d0*/
  do /*0xffde80d9*/
  {
    __inbyte(0x61u); /*0xffde80d5*/
    --n40_1; /*0xffde80d6*/
  }
  while ( n40_1 ); /*0xffde80d9*/
  GpioData2 = __inbyte(0x2Fu); /*0xffde80e1*/
  if ( GpioData2 == 2 ) /*0xffde80e4*/
    BoardId = 1; /*0xffde80e6*/
  IoDelayCount2 = 40; /*0xffde80e8*/
  do /*0xffde80f1*/
  {
    __inbyte(0x61u); /*0xffde80ed*/
    --IoDelayCount2; /*0xffde80ee*/
  }
  while ( IoDelayCount2 ); /*0xffde80f1*/
  __outbyte(0x2Eu, 0xA5u); /*0xffde80f8*/
  do /*0xffde8100*/
  {
    __inbyte(0x61u); /*0xffde80fc*/
    --IoDelayCount; /*0xffde80fd*/
  }
  while ( IoDelayCount ); /*0xffde8100*/
  __outbyte(0x2Eu, 7u); /*0xffde8107*/
  __outbyte(0x2Fu, 3u); /*0xffde8110*/
  GpioData3 = __inbyte(0x2Fu); /*0xffde8111*/
  if ( GpioData3 == 3 ) /*0xffde8114*/
    BoardId |= 2u; /*0xffde8116*/
  return BoardId; /*0xffde8119*/
}


// Function: GetPlatformInfoFromPdr @ 0xffde8121 (0xd9 bytes)
// Index: 8/50

int __fastcall GetPlatformInfoFromPdr(int a1, int a2)
{
  int Status; // eax
  int Status_1; // esi
  int ReportProtocol; // eax
  int Status_2; // eax
  int ReportProtocol2; // eax
  unsigned __int8 PlatformId; // al
  int DataPtr; // [esp+8h] [ebp-4h] BYREF

  Status = (*(int (__cdecl **)(int, void *, _DWORD, _DWORD, int *))(*(_DWORD *)a1 + 32))( /*0xffde8139*/
             a1,
             &unk_FFDEA9E8,
             0,
             0,
             &DataPtr);
  Status_1 = Status; /*0xffde813c*/
  if ( Status >= 0 )
  {
    Status_2 = (*(int (__cdecl **)(int, int, _DWORD, int, int))(DataPtr + 4))(DataPtr, 4, 0, 4102, a2); /*0xffde8187*/
    Status_1 = Status_2; /*0xffde818a*/
    if ( Status_2 >= 0 )
    {
      PlatformId = *(_BYTE *)(a2 + 37); /*0xffde81c0*/
      if ( PlatformId > 0x17u )
      {
        ReportStatusCode( /*0xffde81e1*/
          0x80000000,
          (int)"PIT from SPI PDR reports Platform ID as %x. This is unknown ID. Assuming Greencity Platform!\n",
          PlatformId);
        *(_BYTE *)(a2 + 37) = -1; /*0xffde81e6*/
        return -2147483623; /*0xffde81ea*/
      }
      else
      {
        ReportStatusCode(0x80000000, (int)"Platform Info from PDR: Type = %x\n", PlatformId);
      }
    }
    else
    {
      ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status_2); /*0xffde819e*/
      ReportProtocol2 = GetReportStatusCodeProtocol(); /*0xffde81a6*/
      if ( ReportProtocol2 ) /*0xffde81ad*/
        (*(void (__cdecl **)(const char *, int, const char *))(ReportProtocol2 + 4))( /*0xffde81b9*/
          "e:\\hs\\PurleyRpPkg\\Platform\\Pei\\PlatformInfo\\PlatformInfo.c",
          279,
          "!EFI_ERROR (Status)");
    }
  }
  else
  {
    ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", Status); /*0xffde8150*/
    ReportProtocol = GetReportStatusCodeProtocol(); /*0xffde8158*/
    if ( ReportProtocol ) /*0xffde815f*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportProtocol + 4))( /*0xffde8174*/
        "e:\\hs\\PurleyRpPkg\\Platform\\Pei\\PlatformInfo\\PlatformInfo.c",
        263,
        "!EFI_ERROR (Status)");
  }
  return Status_1; /*0xffde81f2*/
}


// Function: PciCfgInitPciBridge @ 0xffde81fa (0x42 bytes)
// Index: 9/50

unsigned int PciCfgInitPciBridge()
{
  int PciBase; // esi
  int BridgeCount; // edi
  int PciBase_1; // edx
  _DWORD *BridgeCmdReg; // ecx
  unsigned int CmdValue; // eax

  PciBase = 1120; /*0xffde81ff*/
  BridgeCount = 2; /*0xffde8209*/
  do /*0xffde8236*/
  {
    PciBase_1 = (unsigned __int16)PciBase; /*0xffde820a*/
    PciBase += 8; /*0xffde820d*/
    *(_DWORD *)(PciBase_1 | 0xFDAE0000) = *(_DWORD *)(PciBase_1 | 0xFDAE0000) & 0x3F61E0FE | 0x80000101; /*0xffde8220*/
    BridgeCmdReg = (_DWORD *)((unsigned __int16)(PciBase_1 + 4) | 0xFDAE0000); /*0xffde8228*/
    CmdValue = *BridgeCmdReg & 0xFFFFC3FF; /*0xffde822c*/
    *BridgeCmdReg = CmdValue; /*0xffde8231*/
    --BridgeCount; /*0xffde8233*/
  }
  while ( BridgeCount ); /*0xffde8236*/
  return CmdValue; /*0xffde8238*/
}


// Function: GetBoardIdFromGpio @ 0xffde823c (0x42a bytes)
// Index: 10/50

int __fastcall GetBoardIdFromGpio(int a1, int a2)
{
  int ReportProtocol; // eax
  int PciBase; // edi
  int BridgeCount; // ebx
  int PciBase_1; // edx
  int Status; // eax
  unsigned __int8 GpioBits; // al
  unsigned int BoardId; // edi
  void *Tmp; // ecx
  unsigned __int8 GpioBits_2; // al
  int Tmp_1; // ebx
  int (__cdecl **PcdProtocol)(int, int); // eax
  int Status_4; // eax
  int Status_1; // esi
  int ReportProtocol2; // eax
  void *PcdArg; // ecx
  int (__cdecl **PcdProtocol2)(int, int); // eax
  int Status_2; // eax
  int ReportProtocol3; // eax
  void *PcdArg2; // ecx
  int (__cdecl **PcdProtocol3)(int, int); // eax
  int Status_3; // eax
  int ReportProtocol4; // eax
  char GpioRaw; // [esp+17h] [ebp-5h]
  unsigned __int8 GpioBits_1; // [esp+17h] [ebp-5h]
  int GpioValue; // [esp+18h] [ebp-4h] BYREF

  if ( !*(_DWORD *)(*(_DWORD *)a1 + 100) ) /*0xffde8241*/
  {
    ReportProtocol = GetReportStatusCodeProtocol(); /*0xffde824d*/
    if ( ReportProtocol ) /*0xffde8254*/
    ... [13735 chars total]


// Function: ReadClx64LCapIdAndSetPcd @ 0xffde869c (0x71 bytes)
// Index: 11/50

int __thiscall ReadClx64LCapIdAndSetPcd(void *this)
{
  int MmioAddr; // eax
  int v2; // ecx
  int v3; // eax
  int Ptr; // eax

  MmioAddr = PciCfgReadMmioAddr((unsigned __int16)__readmsr(0x300u) >> 8, 30, 3); /*0xffde86b3*/
  v2 = *(_DWORD *)(MmioAddr + 132); /*0xffde86b9*/
  v3 = *(_DWORD *)(MmioAddr + 152); /*0xffde86bf*/
  if ( (v2 & 0x38) == 0x10 && (v3 & 0x600) == 0x600 )
  {
    Ptr = PeiPcdGetPtr((void *)0x600); /*0xffde86d8*/
    (*(void (__cdecl **)(int, int, void *))(Ptr + 60))(35, 17, this); /*0xffde86e1*/
    ReportStatusCode(0x80000000, (int)"ReadClx64LCapIdandSetPcd(): PcdCLX64LCpuValue = CLX64L_CPU_PRESENT\n");
  }
  else
  {
    ReportStatusCode(0x80000000, (int)"ReadClx64LCapIdandSetPcd(): PcdCLX64LCpuValue = 0\n");
  }
  return 0; /*0xffde870c*/
}


// Function: PlatformInfoInit @ 0xffde870d (0x2fd bytes)
// Index: 12/50

int __fastcall PlatformInfoInit(int a1, int *a2)
{
  int v3; // eax
  int v4; // eax
  int v6; // eax
  int v7; // ecx
  int n40; // ecx
  int n40_1; // esi
  int n40_2; // esi
  int n40_3; // esi
  int v12; // edi
  void (__cdecl **v13)(int, _DWORD, int, int, _DWORD, __int16 *); // ebx
  int MatchingSetupGuid; // eax
  int Variable; // eax
  int PlatformInfoFromPdr; // eax
  bool v17; // al
  char BoardIdFromIoPorts; // al
  int v19; // ecx
  int v20; // ecx
  int NextGuidHob; // eax
  int NextGuidHob_1; // ebx
  int v23; // eax
  int ReportStatusCodeProtocol; // eax
  char dst; // [esp+12h] [ebp-2026h] BYREF
  unsigned __int8 v26; // [esp+13h] [ebp-2025h] BYREF
  unsigned int v27; // [esp+14h] [ebp-2024h] BYREF
  __int16 v28; // [esp+18h] [ebp-2020h] BYREF
  int v29; // [esp+1Ch] [ebp-201Ch]
  int *v30; // [esp+20h] [ebp-2018h]
  char v31[4]; // [esp+24h] [ebp-2014h] BYREF
  char src[28]; // [esp+28h] [ebp-2010h] BYREF
  unsigned int v33; // [esp+44h] [ebp-1FF4h]
  char v34; // [esp+48h] [ebp-1FF0h]
  int v35; // [esp+49h] [ebp-1FEFh]
  unsigned __int8 v36; // [esp+4Dh] [ebp-1FEBh]
  __int16 v37; // [esp+50h] [ebp-1FE8h]
  __int16 v38; // [esp+52h] [ebp-1FE6h]
  __int16 v39; // [esp+54h] [ebp-1FE4h]
  __int16 v40; // [esp+56h] [ebp-1FE2h]
  char BoardIdFromIoPorts_1; // [esp+AAh] [ebp-1F8Eh]
  char dst_1; // [esp+ABh] [ebp-1F8Dh]
  __int16 v43; // [esp+B6h] [ebp-1F82h]
  bool v44; // [esp+B8h] [ebp-1F80h]
  bool v45; // [esp+B9h] [ebp-1F7Fh]
  char PchSku; // [esp+BAh] [ebp-1F7Eh]
  char v47; // [esp+BCh] [ebp-1F7Ch]
  char v48; // [esp+BDh] [ebp-1F7Bh]
  char v49[33]; // [esp+1030h] [ebp-1008h] BYREF
  int v50; // [esp+1051h] [ebp-FE7h]
  unsigned __int8 v51; // [esp+1055h] [ebp-FE3h]

  v30 = a2; /*0xffde871f*/
  v3 = *a2; /*0xffde8723*/
  v27 = *(_DWORD *)(*a2 + 100); /*0xffde8728*/
  if ( v27 ) /*0xffde872e*/
  {
    v6 = (*(int (__cdecl **)(int *, void *, _DWORD, _DWORD, char *))(v3 + 32))(a2, &unk_FFDEA9C8, 0, 0, v31); /*0xffde8786*/
    v7 = *a2; /*0xffde8789*/
    v29 = v6; /*0xffde878e*/
    (*(void (__cdecl **)(char *, int, _DWORD))(v7 + 84))(src, 4102, 0); /*0xffde879d*/
    __outbyte(0x2Eu, 0x5Au); /*0xffde87ab*/
    n40 = 40; /*0xffde87ae*/
    n40_1 = 40; /*0xffde87b1*/
    do /*0xffde87bb*/
    {
      __inbyte(0x61u); /*0xffde87b7*/
      --n40_1; /*0xffde87b8*/
    }
    while ( n40_1 ); /*0xffde87bb*/
    __outbyte(0x2Eu, 0x20u); /*0xffde87c5*/
    n40_2 = 40; /*0xffde87c8*/
    do /*0xffde87d2*/
    {
      __inbyte(0x61u); /*0xffde87ce*/
      --n40_2; /*0xffde87cf*/
    }
    while ( n40_2 ); /*0xffde87d2*/
    __inbyte(0x2Fu); /*0xffde87da*/
    n40_3 = 40; /*0xffde87df*/
    do /*0xffde87eb*/
    {
      __inbyte(0x61u); /*0xffde87e7*/
      --n40_3; /*0xffde87e8*/
    }
    while ( n40_3 ); /*0xffde87eb*/
    __outbyte(0x2Eu, 0xA5u); /*0xffde87f5*/
    v12 = (int)v30; /*0xffde87f6*/
    do /*0xffde8804*/
    {
      __inbyte(0x61u); /*0xffde8800*/
      --n40; /*0xffde8801*/
    }
    while ( n40 ); /*0xffde8804*/
    v13 = (void (__cdecl **)(int, _DWORD, int, int, _DWORD, __int16 *))v27; /*0xffde8806*/
    if ( v29 < 0 ) /*0xffde8811*/
      ReportStatusCode(0x80000000, (int)"LocatePpi Error in PlatformInfo.c !\n"); /*0xffde8819*/
    MatchingSetupGuid = FindMatchingSetupGuid(); /*0xffde8820*/
    if ( MatchingSetupGuid == -1 || (Variable = PeiSetupGetVariable((void *)dword_FFDEADE0[3 * MatchingSetupGuid])) == 0 ) /*0xffde8841*/
    {
      dst_1 = 1; /*0xffde885f*/
    }
    else
    {
      CopyMem(&dst, (char *)(Variable + 8), 1u); /*0xffde884c*/
      dst_1 = dst; /*0xffde8856*/
    }
    (*v13)(v12, v13, 1, 2031618, 0, &v28); /*0xffde8877*/
    v38 = v28; /*0xffde887e*/
    v40 = 0; /*0xffde8885*/
    (*v13)(v12, v13, 0, 2031624, 0, (__int16 *)&v26); /*0xffde889a*/
    v39 = v26; /*0xffde88a8*/
    if ( GetBoardIdFromGpio(v12, (int)src) < 0 ) /*0xffde88b6*/
    {
      PlatformInfoFromPdr = GetPlatformInfoFromPdr(v12, (int)v49); /*0xffde88c1*/
      v36 = v51; /*0xffde88cd*/
      v35 = v50; /*0xffde88d8*/
      if ( PlatformInfoFromPdr < 0 ) /*0xffde88de*/
        v36 = -1; /*0xffde88e0*/
    }
    v37 = 0; /*0xffde88e7*/
    v17 = IsGbeEnabled(); /*0xffde88ec*/
    v43 = -256; /*0xffde88f3*/
    v44 = !v17; /*0xffde8901*/
    HIBYTE(v43) = GetGbePortNumber(); /*0xffde890d*/
    v45 = IsGbePhyPresent(); /*0xffde8919*/
    PchSku = GetPchSku(); /*0xffde8925*/
    BoardIdFromIoPorts = ReadBoardIdFromIoPorts(); /*0xffde892c*/
    v27 = 0; /*0xffde8931*/
    BoardIdFromIoPorts_1 = BoardIdFromIoPorts; /*0xffde893d*/
    CpuGetStepping(v19, &v27); /*0xffde8944*/
    v20 = v27; /*0xffde8949*/
    LOBYTE(v20) = v27 & 0xF; /*0xffde895a*/
    v33 = v27 >> 4; /*0xffde895d*/
    v34 = v27 & 0xF; /*0xffde8961*/
    NextGuidHob = GetNextGuidHob(v20, 4126); /*0xffde8965*/
    NextGuidHob_1 = NextGuidHob; /*0xffde896a*/
    if ( NextGuidHob ) /*0xffde896e*/
    {
      SetBoardDefaultSku((void *)(NextGuidHob + 8)); /*0xffde8973*/
      if ( NextGuidHob_1 != -24 ) /*0xffde897d*/
        CopyMem((char *)(NextGuidHob_1 + 24), src, 0x1006u); /*0xffde8988*/
    }
    v23 = (*(int (__cdecl **)(int, void *))(*(_DWORD *)v12 + 24))(v12, &unk_FFDEAAA8); /*0xffde8996*/
    if ( v23 < 0 ) /*0xffde899d*/
    {
      ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v23); /*0xffde89a6*/
      ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde89ae*/
      if ( ReportStatusCodeProtocol ) /*0xffde89b5*/
        (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde89c6*/
          "e:\\hs\\PurleyRpPkg\\Platform\\Pei\\PlatformInfo\\PlatformInfo.c",
          897,
          "!EFI_ERROR (Status)");
    }
    __outbyte(0x72u, 0x18u); /*0xffde89d4*/
    __outbyte(0x73u, v36); /*0xffde89df*/
    __outbyte(0x72u, 0x19u); /*0xffde89e5*/
    __outbyte(0x73u, v47 + 16 * v48); /*0xffde89fa*/
    ReadClx64LCapIdAndSetPcd((void *)0x72); /*0xffde89fb*/
    return 0; /*0xffde8a00*/
  }
  else
  {
    ReportStatusCode(0x80000000, (int)"\nError! PlatformInfoInit() - PeiServices is a NULL Pointer!!!\n"); /*0xffde873b*/
    ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", -2147483646); /*0xffde874a*/
    v4 = GetReportStatusCodeProtocol(); /*0xffde8752*/
    if ( v4 ) /*0xffde8759*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffde876a*/
        "e:\\hs\\PurleyRpPkg\\Platform\\Pei\\PlatformInfo\\PlatformInfo.c",
        771,
        "!EFI_ERROR (((RETURN_STATUS)(0x80000000 | (2))))");
    return -2147483646; /*0xffde8770*/
  }
}


// Function: GetPchSku @ 0xffde8a0a (0x294 bytes)
// Index: 13/50

int GetPchSku()
{
  int n35; // eax
  int MmioAddr; // eax
  char n9; // bl
  unsigned __int16 n0xA1C0; // ax
  int ReportStatusCodeProtocol; // eax
  double v5; // [esp-4h] [ebp-10h]
  int n35_1; // [esp-4h] [ebp-10h]

  n35 = n35; /*0xffde8a0a*/
  if ( n35 == 54 ) /*0xffde8a17*/
  {
    MmioAddr = PciCfgReadMmioAddr(0, 31, 0); /*0xffde8a25*/
    n9 = *(_BYTE *)(MmioAddr + 8); /*0xffde8a2b*/
    n0xA1C0 = IoRead16((unsigned __int16 *)(MmioAddr + 2)); /*0xffde8a31*/
    if ( n0xA1C0 != 0xA142 /*0xffde8af9*/
      && n0xA1C0 != 0xA143
      && n0xA1C0 != 0xA144
      && n0xA1C0 != 0xA145
      && n0xA1C0 != 0xA146
      && n0xA1C0 != 0xA147
      && n0xA1C0 != 0xA148
      && n0xA1C0 != 0xA140
      && n0xA1C0 != 0xA141
      && n0xA1C0 != 0xA14D
      && n0xA1C0 != 0xA14E
      && n0xA1C0 != 0xA14F
      && n0xA1C0 != 0xA149
      && n0xA1C0 != 0xA14A
      && n0xA1C0 != 0xA150
      && n0xA1C0 != 0xA14B )
    {
      if ( n0xA1C0 != 0x9D40 /*0xffde8b43*/
        && n0xA1C0 != 0x9D41
        && n0xA1C0 != 0x9D42
        && n0xA1C0 != 0x9D43
        && n0xA1C0 != 0x9D46
        && n0xA1C0 != 0x9D48 )
      {
        if ( (n0xA1C0 < 0xA1C0u || n0xA1C0 > 0xA1CFu) && n0xA1C0 != 0xA243 && (n0xA1C0 < 0xA240u || n0xA1C0 > 0xA24Fu) ) /*0xffde8b89*/
          return 54; /*0xffde8b89*/
        if ( *(_BYTE *)(GetPchSeriesFromPcd((void *)n0xA1C0) + 252) == 4 && !n9 || !n9 ) /*0xffde8baf*/
          return 48; /*0xffde8ba2*/
        switch ( n9 ) /*0xffde8bb5*/
        {
          case 2: /*0xffde8bb5*/
            return 49; /*0xffde8c13*/
          case 3: /*0xffde8bb5*/
            return 50; /*0xffde8c0f*/
          case 4: /*0xffde8bb5*/
            return 51; /*0xffde8c0b*/
          case 8: /*0xffde8bb5*/
            return 52; /*0xffde8c07*/
        }
        if ( n9 != 9 ) /*0xffde8bc9*/
        {
          ReportStatusCode( /*0xffde8bda*/
            0x80000000,
            (int)"Unsupported PCH Stepping. Supporting PCH stepping starting from %s and above\n",
            "LbgA0");
          ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde8be2*/
          if ( ReportStatusCodeProtocol ) /*0xffde8be9*/
            (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde8bfe*/
              "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchInfoLib\\PchInfoLib.c",
              167,
              "((BOOLEAN)(0==1))");
          return 54; /*0xffde8c01*/
        }
        return 53; /*0xffde8ba5*/
      }
      switch ( n9 ) /*0xffde8c1d*/
      {
        case 16: /*0xffde8c1d*/
          n35_1 = 35; /*0xffde8c41*/
          break;
        case 17: /*0xffde8c1d*/
          n35_1 = 36; /*0xffde8c3d*/
          break;
        case 32: /*0xffde8c1d*/
          n35_1 = 37; /*0xffde8c39*/
          break;
        case 33: /*0xffde8c1d*/
          n35_1 = 38; /*0xffde8c35*/
          break;
        default:
          LODWORD(v5) = "PchLpB0"; /*0xffde8c2e*/
LABEL_61:
          ReportStatusCode( /*0xffde8c65*/
            0x80000000,
            (int)"Unsupported PCH Stepping. Supporting PCH stepping starting from %a and above\n",
            v5);
          return 54; /*0xffde8c79*/
      }
      goto LABEL_66; /*0xffde8c37*/
    }
    if ( n9 ) /*0xffde8c4a*/
    {
      switch ( n9 ) /*0xffde8c4f*/
      {
        case 16: /*0xffde8c4f*/
          n35 = 1; /*0xffde8c8a*/
          goto LABEL_68; /*0xffde8c8a*/
        case 32: /*0xffde8c4f*/
          n35_1 = 2; /*0xffde8c83*/
          break;
        case 48: /*0xffde8c4f*/
          n35_1 = 3; /*0xffde8c7f*/
          break;
        case 49: /*0xffde8c4f*/
          n35_1 = 4; /*0xffde8c7b*/
          break;
        default:
          LODWORD(v5) = "PchHA0"; /*0xffde8c60*/
          goto LABEL_61; /*0xffde8c60*/
      }
LABEL_66:
      n35 = n35_1; /*0xffde8c85*/
LABEL_68:
      n35 = n35; /*0xffde8c8b*/
      return n35; /*0xffde8c90*/
    }
    n35 = 0; /*0xffde8c92*/
    return 0; /*0xffde8c98*/
  }
  return n35; /*0xffde8c9a*/
}


// Function: GetPchSeries @ 0xffde8c9e (0xec bytes)
// Index: 14/50

int GetPchSeries()
{
  int n3; // eax
  int n3_1; // esi
  int MmioAddr; // eax
  unsigned __int16 n0xA1C0; // ax
  int ReportStatusCodeProtocol; // eax

  n3 = n3_0; /*0xffde8c9e*/
  n3_1 = 3; /*0xffde8ca6*/
  if ( n3_0 == 3 )
  {
    MmioAddr = PciCfgReadMmioAddr(0, 31, 0); /*0xffde8cb6*/
    n0xA1C0 = IoRead16((unsigned __int16 *)(MmioAddr + 2)); /*0xffde8cc4*/
    if ( n0xA1C0 >= 0xA1C0u && n0xA1C0 <= 0xA1CFu || n0xA1C0 == 0xA243 || n0xA1C0 >= 0xA240u && n0xA1C0 <= 0xA24Fu )
    {
      n3_1 = 1; /*0xffde8d7f*/
    }
    else if ( n0xA1C0 == 0x9D40
           || n0xA1C0 == 0x9D41
           || n0xA1C0 == 0x9D42
           || n0xA1C0 == 0x9D43
           || n0xA1C0 == 0x9D46
           || n0xA1C0 == 0x9D48 )
    {
      n3_1 = 2; /*0xffde8d7a*/
    }
    else
    {
      ReportStatusCode(0x80000000, (int)"Unsupported PCH SKU, LpcDeviceId: 0x%04x!\n", n0xA1C0);
      ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde8d58*/
      if ( ReportStatusCodeProtocol ) /*0xffde8d5f*/
        (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde8d70*/
          "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchInfoLib\\PchInfoLib.c",
          252,
          "((BOOLEAN)(0==1))");
    }
    n3_0 = n3_1; /*0xffde8d80*/
    return n3_1; /*0xffde8d86*/
  }
  return n3; /*0xffde8d88*/
}


// Function: IsPchLbg @ 0xffde8d8a (0xa9 bytes)
// Index: 15/50

int IsPchLbg()
{
  int n2; // eax
  int n2_1; // esi
  int MmioAddr; // eax
  unsigned __int16 n0xA1C0; // ax
  int ReportStatusCodeProtocol; // eax

  n2 = n2; /*0xffde8d8a*/
  n2_1 = 2; /*0xffde8d92*/
  if ( n2 == 2 )
  {
    MmioAddr = PciCfgReadMmioAddr(0, 31, 0); /*0xffde8da2*/
    n0xA1C0 = IoRead16((unsigned __int16 *)(MmioAddr + 2)); /*0xffde8db0*/
    if ( n0xA1C0 >= 0xA1C0u && n0xA1C0 <= 0xA1CFu || n0xA1C0 == 0xA243 || n0xA1C0 >= 0xA240u && n0xA1C0 <= 0xA24Fu )
    {
      n2_1 = 1; /*0xffde8e28*/
    }
    else
    {
      ReportStatusCode(0x80000000, (int)"Unsupported PCH SKU, LpcDeviceId: 0x%04x!\n", n0xA1C0);
      ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde8e06*/
      if ( ReportStatusCodeProtocol ) /*0xffde8e0d*/
        (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde8e1e*/
          "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchInfoLib\\PchInfoLib.c",
          290,
          "((BOOLEAN)(0==1))");
    }
    n2 = n2_1; /*0xffde8e29*/
    return n2_1; /*0xffde8e2f*/
  }
  return n2; /*0xffde8e31*/
}


// Function: PciCfgReadMmioAddr @ 0xffde8e33 (0x4c bytes)
// Index: 16/50

int __fastcall PciCfgReadMmioAddr(unsigned __int8 a1, char a2, int a3)
{
  _DWORD v4[5]; // [esp+8h] [ebp-14h] BYREF

  v4[2] = 512; /*0xffde8e4a*/
  v4[3] = 0; /*0xffde8e63*/
  v4[1] = 0; /*0xffde8e69*/
  v4[0] = (a3 & 7 | (8 * (a2 & 0x1F | (32 * a1)))) << 12; /*0xffde8e6c*/
  PciCfgAddrEncode(0, 0, v4, &a3); /*0xffde8e6f*/
  return a3; /*0xffde8e7a*/
}


// Function: CpuGetStepping @ 0xffde8e7f (0x47 bytes)
// Index: 17/50

int __fastcall CpuGetStepping(int a1, _DWORD *a2)
{
  _EAX = 1; /*0xffde8e9b*/
  __asm { cpuid } /*0xffde8e9e*/
  if ( a2 ) /*0xffde8ea4*/
    *a2 = _EAX; /*0xffde8ea6*/
  return 1; /*0xffde8ec1*/
}


// Function: GpioGetPadOutputState @ 0xffde8ec6 (0xc6 bytes)
// Index: 18/50

int __cdecl GpioGetPadOutputState(int a1, int a2, int *a3)
{
  int v3; // ecx
  int v4; // ebx
  unsigned int v5; // esi
  unsigned int v6; // edi
  _DWORD *GroupInfo; // ebp
  unsigned int v9; // [esp+10h] [ebp-8h] BYREF
  unsigned int v10; // [esp+14h] [ebp-4h] BYREF

  v4 = v3; /*0xffde8ec9*/
  v5 = BYTE2(v3); /*0xffde8ed3*/
  v6 = (unsigned __int16)v3; /*0xffde8ed6*/
  if ( !GpioIsPadValidForChipset(v3) )
  {
    ReportStatusCode(
      0x80000000,
      (int)"GPIO ERROR: Incorrect GpioPad define used on this chipset (Group=%d, Pad=%d)!\n",
      v5,
      v6);
    return -2147483645; /*0xffde8efb*/
  }
  GroupInfo = GpioGetGroupInfo(&v9); /*0xffde8f09*/
  if ( v5 >= v9 )
  {
    ReportStatusCode(0x80000000, (int)"GPIO ERROR: Group argument (%d) exceeds GPIO group range\n", v5);
    return -2147483646; /*0xffde8f29*/
  }
  v9 = 60 * v5; /*0xffde8f2e*/
  if ( v6 >= GroupInfo[15 * v5 + 14] )
  {
    ReportStatusCode(0x80000000, (int)"GPIO ERROR: Pin number (%d) exceeds possible range for this group\n", v6);
    return -2147483646; /*0xffde8f3e*/
  }
  GpioGetPadOwnership(v4, &v10); /*0xffde8f46*/
  if ( v10 )
  {
    ReportStatusCode(0x80000000, (int)"GPIO ERROR: Accessing pad not owned by host (Group=%d, Pad=%d)!\n", v5, v6);
    return -2147483645; /*0xffde8f59*/
  }
  *a3 = *(_DWORD *)((unsigned __int16)(GroupInfo[v9 / 4 + 13] + 8 * v6) /*0xffde8f81*/
                  | ((LOBYTE(GroupInfo[v9 / 4]) | 0xFFFFFD00) << 16))
      & 2;
  return 0; /*0xffde8f85*/
}


// Function: GpioGetInputValue @ 0xffde8f8c (0x4f bytes)
// Index: 19/50

int __fastcall GpioGetInputValue(int a1, int *a2)
{
  int PadOutputState; // eax
  int PadOutputState_1; // edi
  int ReportStatusCodeProtocol; // eax

  PadOutputState = GpioGetPadOutputState(a1, a1, a2); /*0xffde8f94*/
  PadOutputState_1 = PadOutputState; /*0xffde8f99*/
  if ( PadOutputState < 0 ) /*0xffde8fa0*/
  {
    ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", PadOutputState); /*0xffde8fad*/
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde8fb5*/
    if ( ReportStatusCodeProtocol ) /*0xffde8fbc*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde8fcd*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
        935,
        "!EFI_ERROR (Status)");
  }
  *a2 = (unsigned int)*a2 >> 1; /*0xffde8fd3*/
  return PadOutputState_1; /*0xffde8fd7*/
}


// Function: GpioGetPadOwnership @ 0xffde8fdb (0xc8 bytes)
// Index: 20/50

int __fastcall GpioGetPadOwnership(int a1, unsigned int *a2)
{
  unsigned int v3; // esi
  unsigned int v4; // edi
  _DWORD *GroupInfo; // eax
  int ReportStatusCodeProtocol; // eax
  int v8; // eax
  unsigned int v9; // edx
  unsigned int v10; // [esp+10h] [ebp-4h] BYREF

  v3 = (unsigned __int16)a1; /*0xffde8fe6*/
  v4 = BYTE2(a1); /*0xffde8fee*/
  GroupInfo = GpioGetGroupInfo(&v10); /*0xffde8ff1*/
  if ( v4 >= v10 )
  {
    ReportStatusCode(0x80000000, (int)"GPIO ERROR: Group argument (%d) exceeds GPIO group range\n", v4);
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9011*/
    if ( ReportStatusCodeProtocol ) /*0xffde9018*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde9029*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
        1389,
        "((BOOLEAN)(0==1))");
    return -2147483646; /*0xffde9034*/
  }
  if ( v3 >= GroupInfo[15 * v4 + 14] )
  {
    ReportStatusCode(0x80000000, (int)"GPIO ERROR: Pin number (%d) exceeds possible range for this group\n", v3);
    v8 = GetReportStatusCodeProtocol(); /*0xffde9052*/
    if ( v8 ) /*0xffde9059*/
      (*(void (__cdecl **)(const char *, int, const char *))(v8 + 4))( /*0xffde9065*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
        1398,
        "((BOOLEAN)(0==1))");
    return -2147483646; /*0xffde9065*/
  }
  v9 = (*(_DWORD *)((unsigned __int16)(GroupInfo[15 * v4 + 1] + 4 * (v3 >> 3)) /*0xffde9096*/
                  | ((LOBYTE(GroupInfo[15 * v4]) | 0xFFFFFD00) << 16))
      & (unsigned int)(3 << (4 * (v3 & 7)))) >> (4 * (v3 & 7));
  *a2 = v9; /*0xffde909a*/
  return 0; /*0xffde909d*/
}


// Function: GpioGetGroupInfo @ 0xffde90a3 (0x21 bytes)
// Index: 21/50

void *__thiscall GpioGetGroupInfo(_DWORD *this)
{
  if ( IsPchLbg() == 1 ) /*0xffde90ae*/
  {
    *this = 13; /*0xffde90b0*/
    return &unk_FFDEAAC0; /*0xffde90b6*/
  }
  else
  {
    *this = 0; /*0xffde90bd*/
    return 0; /*0xffde90c0*/
  }
}


// Function: GpioIsPadValidForChipset @ 0xffde90c4 (0x36 bytes)
// Index: 22/50

bool __fastcall GpioIsPadValidForChipset(int a1)
{
  int PchSeries; // eax

  PchSeries = GetPchSeries(); /*0xffde90c7*/
  if ( PchSeries == 1 ) /*0xffde90cf*/
    return (a1 & 0xFF000000) == 0x1000000; /*0xffde90d7*/
  if ( PchSeries != 2 ) /*0xffde90e6*/
    return 0; /*0xffde90e6*/
  return (a1 & 0xFF000000) == 0x2000000; /*0xffde90e1*/
}


// Function: IoRead16 @ 0xffde90fa (0x2e bytes)
// Index: 23/50

int __fastcall IoRead16(unsigned __int16 *MmioAddr)
{
  int ReportStatusCodeProtocol; // eax

  if ( ((unsigned __int8)MmioAddr & 1) != 0 ) /*0xffde9100*/
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9102*/
    if ( ReportStatusCodeProtocol ) /*0xffde9109*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde911a*/
        "e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLib.c",
        151,
        "(Address & 1) == 0");
  }
  return *MmioAddr; /*0xffde9126*/
}


// Function: GetNextGuidHob @ 0xffde9128 (0x50 bytes)
// Index: 24/50

int __fastcall GetNextGuidHob(int a1, int n4126)
{
  int PeiServicesTablePointer; // eax
  int ReportStatusCodeProtocol; // eax
  int v6; // [esp+4h] [ebp-4h] BYREF

  PeiServicesTablePointer = GetPeiServicesTablePointer(); /*0xffde912f*/
  if ( (*(int (__cdecl **)(int, int, int, int *))(*(_DWORD *)PeiServicesTablePointer + 52))( /*0xffde9147*/
         PeiServicesTablePointer,
         4,
         n4126,
         &v6) < 0 )
    v6 = 0; /*0xffde9149*/
  if ( !v6 ) /*0xffde9151*/
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9153*/
    if ( ReportStatusCodeProtocol ) /*0xffde915a*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde916b*/
        "e:\\hs\\MdePkg\\Library\\PeiHobLib\\HobLib.c",
        250,
        "Hob != ((void *) 0)");
  }
  return v6; /*0xffde9144*/
}


// Function: GetReportStatusCodeProtocol @ 0xffde9178 (0x31 bytes)
// Index: 25/50

int GetReportStatusCodeProtocol()
{
  int PeiServicesTablePointer; // eax
  _BYTE v2[4]; // [esp+0h] [ebp-8h] BYREF
  int v3; // [esp+4h] [ebp-4h] BYREF

  PeiServicesTablePointer = GetPeiServicesTablePointer(); /*0xffde917d*/
  if ( (*(int (__cdecl **)(int, void *, _DWORD, _BYTE *, int *))(*(_DWORD *)PeiServicesTablePointer + 32))( /*0xffde919c*/
         PeiServicesTablePointer,
         &unk_FFDEA9D8,
         0,
         v2,
         &v3) >= 0 )
    return v3; /*0xffde91a2*/
  else
    return 0; /*0xffde919e*/
}


// Function: ReportStatusCode @ 0xffde91a9 (0x2a bytes)
// Index: 26/50

int ReportStatusCode(int a1, int a2, ...)
{
  int result; // eax
  int (__cdecl **v3)(int, int, char *); // esi
  va_list va; // [esp+10h] [ebp+Ch] BYREF

  va_start(va, a2);
  result = GetReportStatusCodeProtocol(); /*0xffde91aa*/
  v3 = (int (__cdecl **)(int, int, char *))result; /*0xffde91af*/
  if ( result ) /*0xffde91b3*/
  {
    result = GetReportMode(); /*0xffde91b5*/
    if ( (result & a1) != 0 ) /*0xffde91c0*/
      return (*v3)(a1, a2, (char *)va); /*0xffde91cc*/
  }
  return result; /*0xffde91d1*/
}


// Function: ReportDebugAssert @ 0xffde91d3 (0x1e bytes)
// Index: 27/50

int __fastcall ReportDebugAssert(
        int e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
        int n48,
        int PeiServices____((void__)_0))
{
  int result; // eax

  result = GetReportStatusCodeProtocol(); /*0xffde91d9*/
  if ( result ) /*0xffde91e0*/
    return (*(int (__cdecl **)(int, int, int))(result + 4))( /*0xffde91e8*/
             e:__hs__MdePkg__Library__PeiServicesTablePointerLibIdt__PeiServ,
             n48,
             PeiServices____((void__)_0));
  return result; /*0xffde91ee*/
}


// Function: PeiPcdGetPtr @ 0xffde91f1 (0x58 bytes)
// Index: 28/50

void *__thiscall PeiPcdGetPtr(void *this)
{
  int PeiServicesTablePointer; // eax
  int v2; // eax
  int ReportStatusCodeProtocol; // eax
  void *this_1; // [esp+0h] [ebp-4h]

  this_1 = this; /*0xffde91f4*/
  PeiServicesTablePointer = GetPeiServicesTablePointer(); /*0xffde91f5*/
  v2 = (*(int (__stdcall **)(int))(*(_DWORD *)PeiServicesTablePointer + 32))(PeiServicesTablePointer); /*0xffde920a*/
  if ( v2 < 0 ) /*0xffde9212*/
  {
    ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v2); /*0xffde921f*/
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9227*/
    if ( ReportStatusCodeProtocol ) /*0xffde922e*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde923c*/
        "e:\\hs\\MdePkg\\Library\\PeiPcdLib\\PeiPcdLib.c",
        49,
        "!EFI_ERROR (Status)");
  }
  return this_1; /*0xffde9247*/
}


// Function: PcdGet32 @ 0xffde9249 (0xf bytes)
// Index: 29/50

// (too small: 0xf bytes)


// Function: PcdGet64 @ 0xffde9258 (0xf bytes)
// Index: 30/50

// (too small: 0xf bytes)


// Function: PeiSetupGetVariable @ 0xffde9267 (0x81 bytes)
// Index: 31/50

int __cdecl PeiSetupGetVariable(void *a1)
{
  int v1; // ecx
  int v2; // edi
  int PeiServicesTablePointer; // eax
  int result; // eax
  int v5; // esi
  int v6; // eax
  int ReportStatusCodeProtocol; // eax
  int (__cdecl **v8)(_DWORD, int, void *, _DWORD, void **, int); // [esp+8h] [ebp-4h] BYREF

  v2 = v1; /*0xffde926d*/
  PeiServicesTablePointer = GetPeiServicesTablePointer(); /*0xffde926f*/
  (*(void (__cdecl **)(int, void *, _DWORD, _DWORD, int (__cdecl ***)(_DWORD, int, void *, _DWORD, void **, int)))(*(_DWORD *)PeiServicesTablePointer + 32))( /*0xffde9284*/
    PeiServicesTablePointer,
    &unk_FFDEA9C8,
    0,
    0,
    &v8);
  result = InternalPeiZeroMem(a1); /*0xffde928d*/
  v5 = result; /*0xffde9292*/
  if ( result ) /*0xffde9296*/
  {
    v6 = (*v8)(v8, v2, &unk_FFDEAA88, 0, &a1, result); /*0xffde92a9*/
    if ( v6 < 0 ) /*0xffde92b0*/
    {
      ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v6); /*0xffde92bd*/
      ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde92c5*/
      if ( ReportStatusCodeProtocol ) /*0xffde92cc*/
        (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde92da*/
          "e:\\hs\\PurleyRpPkg\\Library\\SetupLib\\PeiSetupLib.c",
          80,
          "!EFI_ERROR (Status)");
    }
    return v5; /*0xffde92e0*/
  }
  return result; /*0xffde92e2*/
}


// Function: FindMatchingSetupGuid @ 0xffde92e8 (0x3f bytes)
// Index: 32/50

int FindMatchingSetupGuid()
{
  int v0; // esi
  char **v1; // eax

  v0 = 0; /*0xffde92e9*/
  if ( off_FFDEADD8 ) /*0xffde92f1*/
  {
    v1 = (char **)&off_FFDEADD8; /*0xffde92f3*/
    do /*0xffde930d*/
    {
      if ( IsGuidMatch(*v1) ) /*0xffde92fa*/
        break; /*0xffde9301*/
      ++v0; /*0xffde9303*/
      v1 = (char **)(&off_FFDEADD8 + 3 * v0); /*0xffde9307*/
    }
    while ( *v1 ); /*0xffde930d*/
  }
  if ( *(&off_FFDEADD8 + 3 * v0) ) /*0xffde9315*/
    return v0; /*0xffde9323*/
  else
    return -1; /*0xffde931e*/
}


// Function: IsGbeEnabled @ 0xffde9327 (0x41 bytes)
// Index: 33/50

bool IsGbeEnabled()
{
  unsigned int v0; // esi
  int ReportStatusCodeProtocol; // eax

  v0 = *(_DWORD *)(PciCfgReadMmioAddr(0, 31, 5) + 16) & 0xFFFFF000; /*0xffde9338*/
  if ( !v0 ) /*0xffde933e*/
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9340*/
    if ( ReportStatusCodeProtocol ) /*0xffde9347*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde9355*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchGbeLib\\PchGbeLib.c",
        58,
        "SpiBar != 0");
  }
  return *(_DWORD *)(v0 + 96) != 0x7FFF; /*0xffde9363*/
}


// Function: GetGbePortNumber @ 0xffde9368 (0x70 bytes)
// Index: 34/50

int GetGbePortNumber()
{
  int v1; // eax
  int v2; // eax
  int v3; // eax
  int v4; // eax
  int ReportStatusCodeProtocol; // eax

  if ( MEMORY[0xFD130200] >= 0 ) /*0xffde9376*/
    return 0; /*0xffde9376*/
  v1 = (MEMORY[0xFD130200] >> 28) & 7; /*0xffde937e*/
  if ( !v1 ) /*0xffde9384*/
    return 4; /*0xffde93d6*/
  v2 = v1 - 1; /*0xffde9386*/
  if ( !v2 ) /*0xffde9389*/
    return 5; /*0xffde93d2*/
  v3 = v2 - 1; /*0xffde938b*/
  if ( !v3 ) /*0xffde938e*/
    return 6; /*0xffde93ce*/
  v4 = v3 - 1; /*0xffde9390*/
  if ( !v4 ) /*0xffde9393*/
    return 9; /*0xffde93ca*/
  if ( v4 != 1 ) /*0xffde9398*/
  {
    ReportStatusCode(0x80000000, (int)"Invalid GbE port\n"); /*0xffde93a0*/
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde93a7*/
    if ( ReportStatusCodeProtocol ) /*0xffde93ae*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde93bc*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchGbeLib\\PchGbeLib.c",
        94,
        "((BOOLEAN)(0==1))");
    return 0; /*0xffde937a*/
  }
  return 12; /*0xffde937a*/
}


// Function: IsGbePhyPresent @ 0xffde93d8 (0xf5 bytes)
// Index: 35/50

bool IsGbePhyPresent()
{
  int ReportStatusCodeProtocol; // eax
  _DWORD *MmioAddr; // esi
  int PeiServicesTablePointer; // eax
  int v3; // eax
  int v4; // eax
  int v6; // [esp+Ch] [ebp-Ch] BYREF
  int v7; // [esp+10h] [ebp-8h] BYREF
  unsigned int v8; // [esp+14h] [ebp-4h] BYREF

  v7 = 0; /*0xffde93e5*/
  v8 = 0; /*0xffde93e8*/
  PchPwrmBaseGet(&v8); /*0xffde93eb*/
  if ( v8 ) /*0xffde93f5*/
  {
    if ( (*(_DWORD *)(v8 + 300) & 0x8000) != 0 ) /*0xffde94c3*/
      return 0; /*0xffde94c3*/
  }
  else
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde93fb*/
    if ( ReportStatusCodeProtocol ) /*0xffde9402*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde9413*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchPmcLib\\PchPmcLib.c",
        162,
        "PchPwrmBase != 0");
  }
  MmioAddr = (_DWORD *)PciCfgReadMmioAddr(0, 31, 6); /*0xffde9426*/
  PeiServicesTablePointer = GetPeiServicesTablePointer(); /*0xffde9428*/
  v3 = (*(int (__cdecl **)(int, void *, _DWORD, _DWORD, int *))(*(_DWORD *)PeiServicesTablePointer + 32))( /*0xffde943b*/
         PeiServicesTablePointer,
         &unk_FFDEA9E8,
         0,
         0,
         &v7);
  if ( v3 < 0 ) /*0xffde9443*/
  {
    ReportStatusCode(0x80000000, (int)"\nASSERT_EFI_ERROR (Status = %r)\n", v3); /*0xffde9450*/
    v4 = GetReportStatusCodeProtocol(); /*0xffde9458*/
    if ( v4 ) /*0xffde945f*/
      (*(void (__cdecl **)(const char *, int, const char *))(v4 + 4))( /*0xffde9470*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchGbeLib\\PchGbeLib.c",
        134,
        "!EFI_ERROR (Status)");
  }
  if ( ((*(int (__cdecl **)(int, int, int, int *))(v7 + 36))(v7, 476, 4, &v6) < 0 || (v6 & 0x4000) == 0) /*0xffde94a1*/
    && GetGbePortNumber()
    && IsGbeEnabled() )
  {
    return *MmioAddr != -1; /*0xffde94b7*/
  }
  return 0; /*0xffde94b2*/
}


// Function: GetReportMode @ 0xffde94cd (0x4f bytes)
// Index: 36/50

int GetReportMode()
{
  unsigned __int8 v0; // al
  char n3; // al
  char n3_1; // cl

  v0 = __inbyte(0x70u); /*0xffde94d3*/
  __outbyte(0x70u, v0 & 0x80 | 0x4A); /*0xffde94d8*/
  n3 = __inbyte(0x71u); /*0xffde94df*/
  n3_1 = n3; /*0xffde94e0*/
  if ( (unsigned __int8)n3 <= 3u ) /*0xffde94e5*/
  {
LABEL_4:
    if ( !n3_1 ) /*0xffde9500*/
      return 0; /*0xffde9500*/
    goto LABEL_5; /*0xffde9500*/
  }
  n3_1 = n3; /*0xffde94e7*/
  if ( !n3 ) /*0xffde94ef*/
  {
    n3_1 = MEMORY[0xFDAF0490] & 2 | 1; /*0xffde94fb*/
    goto LABEL_4; /*0xffde94fb*/
  }
LABEL_5:
  if ( n3_1 != -1 )
    return n3_1 != 1 ? -2147483578 : -2147483644;
  return 0; /*0xffde9518*/
}


// Function: GetPeiServicesTablePointer @ 0xffde951c (0x32 bytes)
// Index: 37/50

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

  ReadIdtr(v2); /*0xffde9525*/
  v0 = *(_DWORD *)(v3 - 4); /*0xffde952d*/
  if ( !v0 ) /*0xffde9532*/
    ReportDebugAssert( /*0xffde9541*/
      (int)"e:\\hs\\MdePkg\\Library\\PeiServicesTablePointerLibIdt\\PeiServicesTablePointer.c",
      48,
      (int)"PeiServices != ((void *) 0)");
  return v0; /*0xffde9549*/
}


// Function: PeiPcdGetPtrByToken @ 0xffde954e (0x2a bytes)
// Index: 38/50

int __thiscall PeiPcdGetPtrByToken(void *this)
{
  int PeiServicesTablePointer; // eax
  int v4; // [esp+4h] [ebp-4h] BYREF

  PeiServicesTablePointer = GetPeiServicesTablePointer(); /*0xffde9555*/
  if ( (*(int (__cdecl **)(int, void *, int *))(*(_DWORD *)PeiServicesTablePointer + 76))( /*0xffde956b*/
         PeiServicesTablePointer,
         this,
         &v4) >= 0 )
    return v4; /*0xffde9571*/
  else
    return 0; /*0xffde956d*/
}


// Function: InternalPeiZeroMem @ 0xffde9578 (0x18 bytes)
// Index: 39/50

int __thiscall InternalPeiZeroMem(void *this)
{
  int buf_1; // eax
  void *this_1; // edx
  unsigned int this_2; // edi
  void *buf; // esi
  int ReportStatusCodeProtocol; // eax

  buf_1 = PeiPcdGetPtrByToken(this); /*0xffde957b*/
  if ( buf_1 ) /*0xffde9582*/
  {
    this_1 = this; /*0xffde9584*/
    this_2 = (unsigned int)this; /*0xffde9644*/
    buf = (void *)buf_1; /*0xffde9646*/
    if ( this_1 ) /*0xffde964a*/
    {
      if ( this_2 > -buf_1 ) /*0xffde9677*/
      {
        ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9679*/
        if ( ReportStatusCodeProtocol ) /*0xffde9680*/
          (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde968a*/
            "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
            54,
            "Length <= (0xFFFFFFFF - (UINTN)Buffer + 1)");
      }
      return (int)InternalZeroMem(buf, this_2); /*0xffde9692*/
    }
  }
  return buf_1; /*0xffde958e*/
}


// Function: PciCfgAddrEncode @ 0xffde9590 (0x1e bytes)
// Index: 40/50

int *__cdecl PciCfgAddrEncode(int a1, int a2, _DWORD *a3, int *a4)
{
  int v4; // ecx

  v4 = PciCfgAddrDecode((int)a3) + (*a3 & 0xFFFFFFF); /*0xffde95a4*/
  *a4 = v4; /*0xffde95ab*/
  return a4; /*0xffde95aa*/
}


// Function: PchPwrmBaseGet @ 0xffde95ae (0x94 bytes)
// Index: 41/50

int __thiscall PchPwrmBaseGet(unsigned int *this)
{
  int v2; // eax
  int MmioAddr; // edi
  int ReportStatusCodeProtocol; // eax

  if ( this ) /*0xffde95b5*/
  {
    MmioAddr = PciCfgReadMmioAddr(0, 31, 2); /*0xffde95fa*/
    if ( (unsigned __int16)IoRead16((unsigned __int16 *)MmioAddr) == 0xFFFF ) /*0xffde960b*/
    {
      ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde960d*/
      if ( ReportStatusCodeProtocol ) /*0xffde9614*/
        (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde9625*/
          "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchCycleDecodingLib\\PchCycleDecodingLib.c",
          303,
          "((BOOLEAN)(0==1))");
      return -2147483645; /*0xffde962b*/
    }
    else
    {
      *this = *(_DWORD *)(MmioAddr + 72) & 0xFFFF0000; /*0xffde963a*/
      return 0; /*0xffde963c*/
    }
  }
  else
  {
    ReportStatusCode(0x80000000, (int)"PchPwrmBaseGet Error. Invalid pointer.\n"); /*0xffde95c1*/
    v2 = GetReportStatusCodeProtocol(); /*0xffde95c8*/
    if ( v2 ) /*0xffde95cf*/
      (*(void (__cdecl **)(const char *, int, const char *))(v2 + 4))( /*0xffde95e0*/
        "e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchCycleDecodingLib\\PchCycleDecodingLib.c",
        293,
        "((BOOLEAN)(0==1))");
    return -2147483646; /*0xffde95e6*/
  }
}


// Function: SetBoardDefaultSku @ 0xffde969d (0x31 bytes)
// Index: 42/50

void *__thiscall SetBoardDefaultSku(void *this)
{
  __int64 Unaligned64; // rax
  __int64 Unaligned64_1; // rax

  Unaligned64 = ReadUnaligned64(&unk_FFDEAA28); /*0xffde96a5*/
  WriteUnaligned64(Unaligned64, SHIDWORD(Unaligned64)); /*0xffde96ae*/
  Unaligned64_1 = ReadUnaligned64(&unk_FFDEAA30); /*0xffde96b8*/
  WriteUnaligned64(Unaligned64_1, SHIDWORD(Unaligned64_1)); /*0xffde96c2*/
  return this; /*0xffde96cc*/
}


// Function: IsGuidMatch @ 0xffde96ce (0x5c bytes)
// Index: 43/50

bool __thiscall IsGuidMatch(char *this)
{
  __int64 Unaligned64; // rax
  int Unaligned64_1; // ebx
  __int64 Unaligned64_3; // rax
  int Unaligned64_2; // edi
  __int64 v6; // kr00_8
  __int64 v7; // rax
  int v9; // [esp+10h] [ebp-8h]
  int v10; // [esp+14h] [ebp-4h]

  Unaligned64 = ReadUnaligned64(this); /*0xffde96d6*/
  v10 = HIDWORD(Unaligned64); /*0xffde96e0*/
  Unaligned64_1 = Unaligned64; /*0xffde96e4*/
  Unaligned64_3 = ReadUnaligned64(&unk_FFDEAA88); /*0xffde96e6*/
  v9 = HIDWORD(Unaligned64_3); /*0xffde96ee*/
  Unaligned64_2 = Unaligned64_3; /*0xffde96f2*/
  v6 = ReadUnaligned64(this + 8); /*0xffde9700*/
  v7 = ReadUnaligned64(&unk_FFDEAA90); /*0xffde9702*/
  return Unaligned64_1 == Unaligned64_2 && v10 == v9 && v6 == v7; /*0xffde9723*/
}


// Function: CopyMem @ 0xffde972a (0x6f bytes)
// Index: 44/50

char *__fastcall CopyMem(char *dst, char *src, unsigned int n4102)
{
  int ReportStatusCodeProtocol; // eax
  int v6; // eax

  if ( n4102 - 1 > -1 - (int)dst ) /*0xffde9740*/
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde9742*/
    if ( ReportStatusCodeProtocol ) /*0xffde9749*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde9757*/
        "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
        56,
        "(Length - 1) <= (0xFFFFFFFF - (UINTN)DestinationBuffer)");
  }
  if ( n4102 - 1 > -1 - (int)src ) /*0xffde9761*/
  {
    v6 = GetReportStatusCodeProtocol(); /*0xffde9763*/
    if ( v6 ) /*0xffde976a*/
      (*(void (__cdecl **)(const char *, int, const char *))(v6 + 4))( /*0xffde9778*/
        "e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
        57,
        "(Length - 1) <= (0xFFFFFFFF - (UINTN)SourceBuffer)");
  }
  if ( dst == src ) /*0xffde9780*/
    return dst; /*0xffde9782*/
  else
    return InternalCopyMem(dst, src, n4102); /*0xffde978c*/
}


// Function: ReadIdtr @ 0xffde9799 (0x23 bytes)
// Index: 45/50

void *__thiscall ReadIdtr(void *this)
{
  void *this_1; // eax

  if ( !this ) /*0xffde979f*/
    ReportDebugAssert((int)"e:\\hs\\MdePkg\\Library\\BaseLib\\X86ReadIdtr.c", 37, (int)"Idtr != ((void *) 0)"); /*0xffde97ae*/
  this_1 = this; /*0xffde97b4*/
  __sidt(this); /*0xffde97b7*/
  return this_1; /*0xffde97bb*/
}


// Function: ReadUnaligned64 @ 0xffde97bc (0x2c bytes)
// Index: 46/50

__int64 __thiscall ReadUnaligned64(void *this)
{
  int ReportStatusCodeProtocol; // eax

  if ( !this ) /*0xffde97c1*/
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde97c3*/
    if ( ReportStatusCodeProtocol ) /*0xffde97ca*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde97db*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
        192,
        "Buffer != ((void *) 0)");
  }
  return *(_QWORD *)this; /*0xffde97e6*/
}


// Function: WriteUnaligned64 @ 0xffde97e8 (0x34 bytes)
// Index: 47/50

int __cdecl WriteUnaligned64(int Unaligned64, int a2)
{
  _DWORD *v2; // ecx
  _DWORD *v3; // esi
  int ReportStatusCodeProtocol; // eax

  v3 = v2; /*0xffde97e9*/
  if ( !v2 ) /*0xffde97ed*/
  {
    ReportStatusCodeProtocol = GetReportStatusCodeProtocol(); /*0xffde97ef*/
    if ( ReportStatusCodeProtocol ) /*0xffde97f6*/
      (*(void (__cdecl **)(const char *, int, const char *))(ReportStatusCodeProtocol + 4))( /*0xffde9807*/
        "e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c",
        219,
        "Buffer != ((void *) 0)");
  }
  *v3 = Unaligned64; /*0xffde9815*/
  v3[1] = a2; /*0xffde9817*/
  return Unaligned64; /*0xffde981a*/
}


// Function: PciCfgSegmentInit @ 0xffde981c (0x9b bytes)
// Index: 48/50

int __cdecl PciCfgSegmentInit(_DWORD *a1, int n8)
{
  int v3; // [esp+Ch] [ebp-4h]

  v3 = PcdGet64((void *)6); /*0xffde984c*/
  a1[1] = 16 * n8 + 16; /*0xffde9855*/
  if ( !a1[4] && !a1[5] ) /*0xffde9871*/
  {
    *(_DWORD *)(v3 + 16) = PcdGet32((void *)5); /*0xffde9896*/
    *(_DWORD *)(v3 + 20) = 0; /*0xffde98ad*/
  }
  return 0; /*0xffde98b3*/
}


// Function: PciCfgAddrDecode @ 0xffde98b7 (0x17e bytes)
// Index: 49/50

int __cdecl PciCfgAddrDecode(int a1)
{
  int v2; // [esp+Ch] [ebp-Ch]
  int v3; // [esp+10h] [ebp-8h]
  int v4; // [esp+14h] [ebp-4h]

  if ( *(_DWORD *)(a1 + 12) ) /*0xffde98cc*/
  {
    v3 = *(_DWORD *)(*(_DWORD *)(a1 + 12) + 4 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 255544); /*0xffde99c2*/
    v4 = *(_DWORD *)(*(_DWORD *)(a1 + 12) + 4 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 255560); /*0xffde99de*/
  }
  else
  {
    v2 = PcdGet64((void *)6); /*0xffde98df*/
    if ( *(_DWORD *)(v2 + 4) ) /*0xffde98e5*/
    {
      v3 = *(_DWORD *)(v2 + 16 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 20); /*0xffde9900*/
      v4 = *(_DWORD *)(v2 + 16 * (unsigned __int16)*(_DWORD *)(a1 + 4) + 16); /*0xffde9918*/
    }
    else
    {
      PciCfgSegmentInit(dword_FFDEAE5C, 8); /*0xffde992b*/
      v3 = dword_FFDEAE70[4 * (unsigned __int16)*(_DWORD *)(a1 + 4)]; /*0xffde9946*/
      v4 = dword_FFDEAE6C[4 * (unsigned __int16)*(_DWORD *)(a1 + 4)]; /*0xffde995d*/
      if ( !v4 && !v3 ) /*0xffde996a*/
      {
        v4 = PcdGet32((void *)5); /*0xffde9997*/
        v3 = 0; /*0xffde99a4*/
      }
    }
  }
  if ( !v4 && !v3 ) /*0xffde99eb*/
    return PcdGet32((void *)5); /*0xffde9a18*/
  return v4; /*0xffde9a31*/
}


// Function: GetPchSeriesFromPcd @ 0xffde9a35 (0xc bytes)
// Index: 50/50

// (too small: 0xc bytes)

