// MeExtractSpsConfigOnSetupEnter - decompiled from Platform.efi
unsigned __int64 __fastcall MeExtractSpsConfigOnSetupEnter(_BYTE *SourceBuffer)
{
  int ManufacturingMode; // ebx
  int v4; // ebx
  int v5; // ebx
  int n240; // ebx
  const CHAR8 *ME_TYPE_UNDEF; // rdx
  __int64 v8; // rcx
  unsigned int v9; // r8d
  int n5; // ebx
  unsigned int n2; // eax

  DebugPrint(0x40u, "[ME] MeExtractSpsConfigOnSetupEnter called...\n"); /*0x4810*/
  if ( !SourceBuffer ) /*0x4818*/
  {
    Assert( /*0x482d*/
      (__int64)"e:\\hs\\PurleyRpPkg\\Platform\\Dxe\\Setup\\MeSpsSetup.c",
      408,
      (__int64)"MeRcConfiguration != ((void *) 0)");
    return 0x8000000000000002uLL; /*0x483c*/
  }
  SourceBuffer[51] = GetManufacturingMode(); /*0x4846*/
  ManufacturingMode = GetManufacturingMode(); /*0x485f*/
  DebugPrint(0x40u, "[HECI] %s (MeType is ", (const char *)L"Set MeType on SetupEnter"); /*0x4861*/
  if ( !ManufacturingMode ) /*0x4868*/
  {
    ME_TYPE_UNDEF = "ME_TYPE_UNDEF"; /*0x48b1*/
    goto LABEL_14; /*0x48b1*/
  }
  v4 = ManufacturingMode - 1; /*0x486a*/
  if ( !v4 ) /*0x486d*/
  {
    ME_TYPE_UNDEF = "ME_TYPE_SPS"; /*0x48a8*/
    goto LABEL_14; /*0x48af*/
  }
  v5 = v4 - 1; /*0x486f*/
  if ( !v5 ) /*0x4872*/
  {
    ME_TYPE_UNDEF = "ME_TYPE_WS"; /*0x489f*/
    goto LABEL_14; /*0x48a6*/
  }
  n240 = v5 - 13; /*0x4874*/
  if ( !n240 ) /*0x4877*/
  {
    ME_TYPE_UNDEF = "ME_TYPE_DFX"; /*0x4896*/
LABEL_14:
    DebugPrint(0x40u, ME_TYPE_UNDEF); /*0x48b8*/
    goto LABEL_15; /*0x48bb*/
  }
  if ( n240 == 240 ) /*0x4882*/
    DebugPrint(0x40u, "ME_TYPE_DISABLED"); /*0x4894*/
  else
    DebugPrint(0x40u, "UNKNOWN"); /*0x488b*/
LABEL_15:
  DebugPrint(0x40u, ")\n"); /*0x48c0*/
  v9 = *(_DWORD *)(ReadCpuPciCfg(v8, 22, 0) + 64); /*0x48db*/
  if ( (v9 & 0xF) == 0xF ) /*0x48e7*/
  {
    n5 = 5; /*0x48e9*/
  }
  else
  {
    n2 = HIWORD(v9) & 0xF; /*0x48f6*/
    if ( !n2 ) /*0x48f9*/
      goto LABEL_25; /*0x48f9*/
    n5 = 2; /*0x48fb*/
    if ( n2 == 2 ) /*0x4902*/
      goto LABEL_26; /*0x4902*/
    n5 = 3; /*0x4904*/
    if ( n2 == 3 ) /*0x490b*/
      goto LABEL_26; /*0x490b*/
    if ( n2 > 3 ) /*0x490d*/
    {
      if ( n2 <= 5 ) /*0x4916*/
      {
        n5 = 4; /*0x4924*/
        goto LABEL_26; /*0x4929*/
      }
      if ( n2 == 15 ) /*0x491b*/
      {
LABEL_25:
        n5 = 0; /*0x492b*/
        goto LABEL_26; /*0x492b*/
      }
    }
    n5 = 6; /*0x491d*/
  }
LABEL_26:
  DebugPrint(0x40u, "[HECI] MEFS1: %08X -> MeMode %d\n", v9, n5);
  SourceBuffer[52] = n5; /*0x494d*/
  DebugPrint(0x40u, "[ME] MeFirmwareMode is set to %d\n", (unsigned __int8)n5); /*0x4950*/
  ExtractMeSpsConfig((__int64)SourceBuffer); /*0x4958*/
  return 0; /*0x4969*/
}
