Newer
Older
AMI-Aptio-BIOS-Reversed / CRBDxe / CRBDxe.c
@Ajax Dong Ajax Dong 2 days ago 55 KB Init
/*
 * CRBDxe - recovered DXE driver source.
 *
 * Source style notes:
 * - Function addresses and indexes are preserved from the IDA regeneration.
 * - Names and signatures are only partially recovered; do not treat every
 *   decompiler type as original source truth.
 * - The companion header groups valid recovered prototypes for navigation.
 */

#include "CRBDxe.h"

// Total recovered functions: 45

// Function: InternalMemCopyMem @ 0x2a0 (0x42 bytes)
// Index: 1/45

char *__fastcall InternalMemCopyMem(char *dst, char *src, unsigned __int64 count)
{
  char *dst_1; // rax
  unsigned __int64 count_1; // rcx
  char *dst_2; // rdi
  char *src_1; // rsi

  dst_1 = dst; /*0x2b0*/
  if ( src < dst && &src[count - 1] >= dst ) /*0x2b8*/
  {
    src_1 = &src[count - 1]; /*0x2d0*/
    dst_2 = &dst[count - 1]; /*0x2d3*/
  }
  else
  {
    count_1 = count; /*0x2ba*/
    count &= 7u; /*0x2bd*/
    count_1 >>= 3; /*0x2c4*/
    qmemcpy(dst, src, 8 * count_1); /*0x2c8*/
    src_1 = &src[8 * count_1]; /*0x2c8*/
    dst_2 = &dst[8 * count_1]; /*0x2c8*/
  }
  qmemcpy(dst_2, src_1, count); /*0x2dc*/
  return dst_1; /*0x2df*/
}

// Function: MemCopyForward @ 0x2f0 (0x11 bytes)
// Index: 2/45

void *__fastcall MemCopyForward(void *buf, unsigned __int64 count, char value)
{
  memset(buf, value, count); /*0x2fa*/
  return buf; /*0x2ff*/
}

// Function: MemCopyBackward @ 0x310 (0x20 bytes)
// Index: 3/45

char *__fastcall MemCopyBackward(char *buf, unsigned __int64 a2)
{
  memset(buf, 0, 8 * (a2 >> 3)); /*0x326*/
  memset(&buf[8 * (a2 >> 3)], 0, a2 & 7); /*0x32b*/
  return buf; /*0x32e*/
}

// Function: _ModuleEntryPoint @ 0x390 (0x1c bytes)
// Index: 4/45

EFI_STATUS ModuleEntryPoint(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  __int64 v3; // rcx
  __int64 v4; // r8
  __int64 v5; // r9

  UefiBootServicesTableLibConstructor((__int64)ImageHandle, (__int64)SystemTable); /*0x399*/
  return PchRcConfigDriverEntry(v3, SystemTable, v4, v5); /*0x3a6*/
}

// Function: UefiBootServicesTableLibConstructor @ 0x3ac (0x22d bytes)
// Index: 5/45

char *__fastcall UefiBootServicesTableLibConstructor(__int64 ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
  signed __int64 v3; // rax
  __int64 v4; // rbx
  __int64 v5; // rax
  __int64 v6; // rax
  __int64 v7; // rax
  char *src; // rbx
  __int64 v9; // rax
  __int64 v10; // rax
  char *n16; // rax

  ::ImageHandle = ImageHandle; /*0x3bb*/
  if ( !ImageHandle ) /*0x3cf*/
    AssertCpuDeadLoop( /*0x3de*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      51,
      (__int64)"gImageHandle != ((void *) 0)");
  SystemTable_0 = (__int64)SystemTable; /*0x3e3*/
  if ( !SystemTable ) /*0x3ed*/
    AssertCpuDeadLoop( /*0x3fc*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      57,
      (__int64)"gST != ((void *) 0)");
  BootServices_0 = (__int64)SystemTable->BootServices; /*0x405*/
  if ( !BootServices_0 ) /*0x40f*/
    AssertCpuDeadLoop( /*0x41e*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiBootServicesTableLib\\UefiBootServicesTableLib.c",
      63,
      (__int64)"gBS != ((void *) 0)");
  RuntimeServices_0 = (__int64)SystemTable->RuntimeServices; /*0x427*/
  if ( !RuntimeServices_0 ) /*0x431*/
    AssertCpuDeadLoop( /*0x444*/
      (__int64)"e:\\hs\\MdePkg\\Library\\UefiRuntimeServicesTableLib\\UefiRuntimeServicesTableLib.c",
      47,
      (__int64)"gRT != ((void *) 0)");
  v3 = DxeServicesTableRegister((__int64)&unk_3930, &qword_3CE8); /*0x457*/
  v4 = v3; /*0x463*/
  if ( v3 < 0 ) /*0x46e*/
  {
    DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v3); /*0x478*/
    AssertCpuDeadLoop( /*0x490*/
      (__int64)"e:\\hs\\MdePkg\\Library\\DxeServicesTableLib\\DxeServicesTableLib.c",
      64,
      (__int64)"!EFI_ERROR (Status)");
  }
  if ( !qword_3CE8 ) /*0x49d*/
    AssertCpuDeadLoop( /*0x4b2*/
      (__int64)"e:\\hs\\MdePkg\\Library\\DxeServicesTableLib\\DxeServicesTableLib.c",
      65,
      (__int64)"gDS != ((void *) 0)");
  if ( v4 < 0 ) /*0x4ba*/
  {
    DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v4); /*0x4c5*/
    AssertCpuDeadLoop( /*0x4dd*/
      (__int64)"e:\\hs\\Build\\HR6N0XMLK\\DEBUG_VS2015\\X64\\AmiCRBPkg\\CRB\\CRBDxe\\DEBUG\\AutoGen.c",
      359,
      (__int64)"!EFI_ERROR (Status)");
  }
  if ( !qword_3CF0 ) /*0x4ea*/
  {
    v5 = (*(__int64 (__fastcall **)(void *, _QWORD, __int64 *))(BootServices_0 + 320))(&unk_38D0, 0, &qword_3CF0); /*0x503*/
    if ( v5 < 0 ) /*0x50c*/
    {
      DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v5); /*0x517*/
      AssertCpuDeadLoop( /*0x52f*/
        (__int64)"e:\\hs\\CpRcPkg\\Library\\DxeMmPciBaseLib\\DxeMmPciBaseLib.c",
        52,
        (__int64)"!EFI_ERROR (Status)");
    }
    if ( !qword_3CF0 ) /*0x53c*/
      AssertCpuDeadLoop( /*0x551*/
        (__int64)"e:\\hs\\CpRcPkg\\Library\\DxeMmPciBaseLib\\DxeMmPciBaseLib.c",
        53,
        (__int64)"mPciUsra != ((void *) 0)");
  }
  SmbiosType9GetSlotConfig(); /*0x556*/
  v6 = CompareMemWrapper(); /*0x55b*/
  qword_3D00 = (*(__int64 (__fastcall **)(__int64))(v6 + 32))(5); /*0x568*/
  v7 = CompareMemWrapper(); /*0x56f*/
  src = (char *)(*(__int64 (__fastcall **)(__int64))(v7 + 40))(7); /*0x57e*/
  v9 = CompareMemWrapper(); /*0x581*/
  if ( (unsigned __int64)(*(__int64 (__fastcall **)(__int64))(v9 + 56))(7) > 0x48 ) /*0x58f*/
    AssertCpuDeadLoop( /*0x5a2*/
      (__int64)"e:\\hs\\AmiCRBPkg\\Library\\AmiPcieSegBusLib\\AmiPcieSegBusDxeSmm.c",
      60,
      (__int64)"sizeof (PCIE_SEG_BUS_TABLE) >= LibPcdGetSize(7U)");
  v10 = CompareMemWrapper(); /*0x5a7*/
  n16 = (char *)(*(__int64 (__fastcall **)(__int64))(v10 + 56))(7); /*0x5af*/
  if ( n16 ) /*0x5b5*/
    return CopyMemWrapper(&dst, src, (unsigned __int64)n16); /*0x5c4*/
  return n16; /*0x5d3*/
}

// Function: PchRcConfigDriverEntry @ 0x5dc (0x111 bytes)
// Index: 6/45

EFI_STATUS __fastcall PchRcConfigDriverEntry(__int64 a1, EFI_SYSTEM_TABLE *SystemTable, __int64 a3, __int64 a4)
{
  EFI_SYSTEM_TABLE *SystemTable_1; // rdx
  __int64 v5; // r9
  EFI_SYSTEM_TABLE *SystemTable_2; // rdx
  __int64 v7; // r9
  __int64 v8; // rax
  char *src; // rax
  __int64 v10; // rbx
  __int64 v11; // rax
  __int64 v12; // rbx
  __int64 v13; // rax
  unsigned int v15[4]; // [rsp+30h] [rbp-20h] BYREF
  char dst[8]; // [rsp+40h] [rbp-10h] BYREF
  __int64 v17; // [rsp+48h] [rbp-8h]
  __int64 v18; // [rsp+60h] [rbp+10h] BYREF
  __int64 v19; // [rsp+70h] [rbp+20h] BYREF
  __int64 v20; // [rsp+78h] [rbp+28h] BYREF

  v18 = a1; /*0x5e1*/
  if ( !::SystemTable ) /*0x5f6*/
  {
    ::SystemTable = (__int64)SystemTable; /*0x5f8*/
    BootServices = (__int64)SystemTable->BootServices; /*0x603*/
    RuntimeServices = (__int64)SystemTable->RuntimeServices; /*0x60e*/
  }
  UefiLibCreateProtocolNotifyEvent( /*0x62c*/
    (__int64)&dword_3900,
    SystemTable,
    (__int64)NotifyFunctionCallback,
    a4,
    (__int64)&v18);
  v15[0] = 770826321; /*0x635*/
  v15[1] = 1325371501; /*0x64c*/
  v15[2] = -433807994; /*0x653*/
  v15[3] = -1627686829; /*0x65a*/
  UefiLibCreateProtocolNotifyEvent((__int64)v15, SystemTable_1, (__int64)CrbDriverEntryPoint, v5, (__int64)&v19); /*0x661*/
  UefiLibCreateProtocolNotifyEvent((__int64)&dword_3940, SystemTable_2, (__int64)PchRcConfigUpdate, v7, (__int64)&v20); /*0x67d*/
  v8 = sub_1A8C(); /*0x682*/
  src = (char *)(*(__int64 (__fastcall **)(__int64))(v8 + 40))(115); /*0x68c*/
  sub_18C4(dst, src, 0x10u); /*0x69c*/
  v10 = *(_QWORD *)dst; /*0x6a1*/
  if ( *(_QWORD *)dst && v17 ) /*0x6af*/
  {
    v11 = sub_1A8C(); /*0x6b1*/
    (*(void (__fastcall **)(__int64, __int64))(v11 + 144))(18, v10); /*0x6be*/
    v12 = v17; /*0x6c4*/
    v13 = sub_1A8C(); /*0x6c8*/
    (*(void (__fastcall **)(__int64, __int64))(v13 + 144))(19, v12); /*0x6d5*/
  }
  OptimizedBootConfig(); /*0x6db*/
  return 0; /*0x6e7*/
}

// Function: PchRcConfigUpdate @ 0x6f0 (0x14f bytes)
// Index: 7/45

__int64 __fastcall PchRcConfigUpdate(__int64 a1)
{
  __int64 result; // rax
  __int64 v3; // r8
  char v4; // al
  __int64 v5; // rax
  __int64 v6; // [rsp+30h] [rbp-D0h] BYREF
  _BYTE v7[83]; // [rsp+40h] [rbp-C0h] BYREF
  char v8; // [rsp+93h] [rbp-6Dh]
  char v9; // [rsp+94h] [rbp-6Ch]
  char v10; // [rsp+105h] [rbp+5h]
  char v11; // [rsp+106h] [rbp+6h]
  char v12; // [rsp+640h] [rbp+540h] BYREF
  __int64 n1495; // [rsp+648h] [rbp+548h] BYREF

  n1495 = 0; /*0x711*/
  v12 = 0; /*0x71e*/
  result = (*(__int64 (__fastcall **)(unsigned int *, _QWORD, __int64 *))(BootServices + 320))(&dword_3940, 0, &v6); /*0x72c*/
  if ( result >= 0 )
  {
    n1495 = 1495; /*0x740*/
    if ( (*(__int64 (__fastcall **)(const __int16 *, void *, _QWORD, __int64 *, _BYTE *))(RuntimeServices + 72))( /*0x775*/
           L"PchRcConfiguration",
           &unk_38C0,
           0,
           &n1495,
           v7) < 0 )
    {
      v9 = 1; /*0x777*/
      v11 = 1; /*0x77b*/
    }
    (*(void (__fastcall **)(__int64, __int64, char *))(v6 + 8))(v6, 8752, &v12); /*0x793*/
    v4 = v12 & 0xFC; /*0x79f*/
    v12 &= 0xFCu; /*0x7a8*/
    if ( v10 == 1 )
    {
      if ( !v11 )
      {
LABEL_9:
        if ( !v9 )
        {
          v4 |= 3u; /*0x7c6*/
LABEL_17:
          v12 = v4; /*0x7ed*/
LABEL_18:
          LOBYTE(v3) = v4; /*0x7f3*/
          v5 = (*(__int64 (__fastcall **)(__int64, __int64, __int64))(v6 + 16))(v6, 8752, v3); /*0x803*/
          if ( v5 >= 0 )
            return (*(__int64 (__fastcall **)(__int64))(BootServices + 112))(a1); /*0x82b*/
          else
            return sub_172C(
                     0x80000000LL,
                     " Get RSTe OROM Boot Info BIOS Services: Unable to write to CMOS variable holding RSTe Boot info. Status %r\n",
                     v5);
        }
LABEL_11:
        if ( v10 == 1 && v11 ) /*0x7d2*/
        {
          v4 |= 1u; /*0x7d7*/
          v12 = v4; /*0x7db*/
        }
        if ( v8 != 1 || !v9 ) /*0x7e9*/
          goto LABEL_18; /*0x7e9*/
        v4 |= 2u; /*0x7eb*/
        goto LABEL_17; /*0x7eb*/
      }
      if ( v8 == 1 && v9 ) /*0x7bc*/
        goto LABEL_18; /*0x7bc*/
    }
    if ( v11 ) /*0x7c0*/
      goto LABEL_11; /*0x7c0*/
    goto LABEL_9; /*0x7c0*/
  }
  return result; /*0x836*/
}

// Function: PciClassCodeQuery @ 0x840 (0x188 bytes)
// Index: 8/45

__int64 PciClassCodeQuery()
{
  __int64 result; // rax
  const char *Get_Class_and_subclass_code_Status___%r_n; // rdx
  __int64 n64; // rcx
  __int64 v3; // [rsp+30h] [rbp-9h] BYREF
  __int64 v4; // [rsp+38h] [rbp-1h] BYREF
  __int64 n8; // [rsp+40h] [rbp+7h] BYREF
  _BYTE v6[11]; // [rsp+50h] [rbp+17h] BYREF
  char n2; // [rsp+5Bh] [rbp+22h]
  unsigned __int8 v8; // [rsp+B0h] [rbp+77h] BYREF
  __int64 v9; // [rsp+B8h] [rbp+7Fh] BYREF

  v9 = 0; /*0x85d*/
  v4 = 0; /*0x866*/
  n8 = 8; /*0x879*/
  result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int64, __int64 *, __int64 *))(BootServices + 176))( /*0x884*/
             1,
             0,
             qword_3CB0,
             &n8,
             &v3);
  if ( result >= 0 ) /*0x88d*/
  {
    result = (*(__int64 (__fastcall **)(__int64, unsigned int *, __int64 *))(BootServices + 152))(v3, &dword_38F0, &v4); /*0x8a9*/
    if ( result >= 0 ) /*0x8b2*/
    {
      result = (*(__int64 (__fastcall **)(__int64, void *, __int64 *))(BootServices + 152))(v3, &unk_3910, &v9); /*0x8ce*/
      if ( result >= 0 ) /*0x8d7*/
      {
        result = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD, __int64, _BYTE *))(v4 + 48))(v4, 0, 0, 64, v6); /*0x8fa*/
        if ( result < 0 ) /*0x900*/
        {
          Get_Class_and_subclass_code_Status___%r_n = "Get Class and subclass code Status = %r\n"; /*0x902*/
LABEL_6:
          n64 = 0x80000000LL; /*0x909*/
          return sub_172C(n64, Get_Class_and_subclass_code_Status___%r_n, result); /*0x9a6*/
        }
        if ( n2 != 2 ) /*0x917*/
          return result; /*0x917*/
        sub_172C(64, "Class code is Network.\n"); /*0x927*/
        if ( n2 == 2 && v6[10] == 8 ) /*0x936*/
          return sub_172C(64, "This is Fabric controller, return..\n"); /*0x93f*/
        result = (*(__int64 (__fastcall **)(__int64, unsigned __int8 *, _QWORD))v9)(v9, &v8, 0); /*0x94f*/
        if ( result < 0 ) /*0x954*/
        {
          Get_Class_and_subclass_code_Status___%r_n = "GetOptionRomPolicy = %r\n"; /*0x956*/
          goto LABEL_6; /*0x95d*/
        }
        sub_172C(64, "OptionRomPolicy  = %d\n", v8); /*0x96e*/
        if ( v8 == 1 ) /*0x977*/
        {
          sub_172C(64, "Oprom policy is UEFI, disable Oprom.\n"); /*0x983*/
          result = (*(__int64 (__fastcall **)(__int64, _QWORD))(v9 + 8))(v9, 0); /*0x991*/
          Get_Class_and_subclass_code_Status___%r_n = "SetOptionRomPolicy  = %r\n"; /*0x994*/
          n64 = 64; /*0x99b*/
          return sub_172C(n64, Get_Class_and_subclass_code_Status___%r_n, result); /*0x99b*/
        }
        return sub_172C(64, "OptionRomPolicy is not UEFI\n"); /*0x9b2*/
      }
    }
  }
  return result; /*0x9bf*/
}

// Function: OptimizedBootConfig @ 0x9c8 (0x1b2 bytes)
// Index: 9/45

__int64 OptimizedBootConfig()
{
  __int64 v0; // rax
  __int64 result; // rax
  __int64 v2; // rax
  EFI_SYSTEM_TABLE *SystemTable; // rdx
  __int64 v4; // r9
  _DWORD v5[4]; // [rsp+30h] [rbp-D0h] BYREF
  _BYTE v6[16]; // [rsp+40h] [rbp-C0h] BYREF
  char v7; // [rsp+50h] [rbp-B0h] BYREF
  unsigned __int8 v8; // [rsp+51h] [rbp-AFh]
  char v9; // [rsp+D1h] [rbp-2Fh]
  unsigned int v10; // [rsp+390h] [rbp+290h] BYREF
  __int64 n814; // [rsp+398h] [rbp+298h] BYREF

  v10 = 0; /*0x9dd*/
  v5[0] = -326642109; /*0xa08*/
  v5[1] = 1270213540; /*0xa17*/
  v5[2] = 1044374945; /*0xa1f*/
  v5[3] = -1458720202; /*0xa27*/
  n814 = 814; /*0xa2f*/
  v0 = (*(__int64 (__fastcall **)(const __int16 *, _DWORD *, unsigned int *, __int64 *, char *))(RuntimeServices + 72))( /*0xa3a*/
         L"Setup",
         v5,
         &v10,
         &n814,
         &v7);
  if ( v0 < 0 ) /*0xa40*/
    return sub_172C(0x80000000LL, "Optimized Boot Get Setup Variable = %r\n", v0); /*0xa51*/
  if ( !v8 ) /*0xa61*/
    return sub_172C(64, "Optimized Boot = %d, Optimized is Disable\n", 0); /*0xb64*/
  sub_172C(64, "Optimized Boot = %d, Optimized is Enabled\n", v8); /*0xa79*/
  if ( v9 == 1 ) /*0xa82*/
  {
    v9 = 0; /*0xaaf*/
    v2 = (*(__int64 (__fastcall **)(const __int16 *, _DWORD *, _QWORD, __int64, char *))(RuntimeServices + 88))( /*0xab3*/
           L"Setup",
           v5,
           v10,
           n814,
           &v7);
    if ( v2 < 0 ) /*0xab9*/
      return sub_172C(0x80000000LL, "Optimized Boot Set Setup Variable = %r\n", v2); /*0xac2*/
    sub_172C(64, "Disable CSM Support.\n"); /*0xace*/
  }
  n814 = 10; /*0xad8*/
  result = (*(__int64 (__fastcall **)(const __int16 *, void *, unsigned int *, __int64 *, _BYTE *))(RuntimeServices + 72))( /*0xb0b*/
             L"NetworkStackVar",
             &unk_3950,
             &v10,
             &n814,
             v6);
  if ( result < 0 ) /*0xb11*/
    return sub_172C(0x80000000LL, "Optimized Boot Get Network Stack Variable = %r\n", result); /*0xb1a*/
  if ( !v6[0] ) /*0xb24*/
  {
    sub_172C(64, "Register protocol notification for PciIoProtocol, to disable Network devices \n"); /*0xb30*/
    return sub_1C50((__int64)&dword_38F0, SystemTable, (__int64)PciClassCodeQuery, v4, (__int64)&qword_3CB0); /*0xb4f*/
  }
  return result; /*0xb71*/
}

// Function: SmbiosType9FillSlotTable @ 0xb7c (0x119 bytes)
// Index: 10/45

__int64 __fastcall SmbiosType9FillSlotTable(
        char n166,
        __int64 a2,
        char a3,
        char a4,
        unsigned __int8 a5,
        char a6,
        char a7)
{
  unsigned __int64 v9; // rdi
  __int64 v10; // rcx
  char *buf; // rax
  char *buf_1; // rbx
  char v13; // al
  int v14; // ecx
  char v15; // al
  int v16; // ecx
  int v17; // ecx
  int v18; // ecx
  int n8; // ecx
  __int64 result; // rax
  __int16 v21; // [rsp+40h] [rbp+18h] BYREF

  LOBYTE(v21) = a3; /*0xb8b*/
  v9 = sub_1858("Slot9"); /*0xba6*/
  buf = (char *)sub_1B18(v10, v9 + 19); /*0xbad*/
  buf_1 = buf; /*0xbb2*/
  if ( buf ) /*0xbb8*/
    buf_1 = sub_19B4(buf, v9 + 19); /*0xbc6*/
  v13 = a6; /*0xbc9*/
  buf_1[11] |= 4u; /*0xbd2*/
  buf_1[12] |= 1u; /*0xbd6*/
  v14 = a5; /*0xbda*/
  buf_1[15] = v13; /*0xbdf*/
  v15 = 8 * a7; /*0xbe6*/
  *(_DWORD *)buf_1 = -61175; /*0xbe9*/
  buf_1[4] = 1; /*0xbef*/
  buf_1[5] = n166; /*0xbf3*/
  buf_1[8] = 3; /*0xbf7*/
  *(_WORD *)(buf_1 + 9) = 9; /*0xbfb*/
  buf_1[16] = v15; /*0xbff*/
  v16 = v14 - 1; /*0xc02*/
  if ( v16 ) /*0xc05*/
  {
    v17 = v16 - 1; /*0xc07*/
    if ( !v17 ) /*0xc0a*/
    {
      buf_1[6] = 9; /*0xc2d*/
      goto LABEL_13; /*0xc30*/
    }
    v18 = v17 - 2; /*0xc0c*/
    if ( !v18 ) /*0xc0f*/
    {
      buf_1[6] = 10; /*0xc27*/
      goto LABEL_13; /*0xc2b*/
    }
    n8 = v18 - 4; /*0xc11*/
    if ( !n8 ) /*0xc14*/
    {
      buf_1[6] = 11; /*0xc21*/
      goto LABEL_13; /*0xc25*/
    }
    if ( n8 == 8 ) /*0xc19*/
    {
      buf_1[6] = 13; /*0xc1b*/
      goto LABEL_13; /*0xc1f*/
    }
  }
  buf_1[6] = 8; /*0xc32*/
LABEL_13:
  buf_1[7] = (a4 != 0) + 3; /*0xc36*/
  sub_17B4((__int64)(buf_1 + 17), "Slot9"); /*0xc4c*/
  v21 = -2; /*0xc5b*/
  result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int16 *, char *))qword_3D78)(qword_3D78, 0, &v21, buf_1); /*0xc6f*/
  if ( result >= 0 ) /*0xc74*/
  {
    sub_1B48((__int64)buf_1); /*0xc79*/
    return 0; /*0xc7e*/
  }
  return result; /*0xc8f*/
}

// Function: PciConfigBitParse @ 0xc98 (0x11b bytes)
// Index: 11/45

__int64 __fastcall PciConfigBitParse(unsigned __int8 a1, char a2, __int64 a3, _BYTE *a4, _BYTE *a5)
{
  unsigned int n0x1000; // edi
  __int64 v9; // rbx
  unsigned __int8 v10; // si
  char n16; // cl
  __int64 v12; // rbx
  unsigned __int16 *v13; // rax
  unsigned __int16 *v14; // rax

  n0x1000 = 0; /*0xcc7*/
  v9 = ((32 * a1) | a2 & 0x1Fu) << 15; /*0xcd3*/
  sub_1E30(v9); /*0xcd6*/
  v10 = *(_BYTE *)sub_1E30((unsigned int)v9 | 0x34LL); /*0xce8*/
  n16 = *(_BYTE *)sub_1E30(v9 | v10); /*0xcf5*/
  while ( n16 ) /*0xd3e*/
  {
    if ( n16 == 16 ) /*0xcfc*/
      goto LABEL_7; /*0xcfc*/
    v12 = ((32LL * a1) | a2 & 0x1F) << 15; /*0xd17*/
    v10 = *(_BYTE *)sub_1E30(v12 | (unsigned __int8)(v10 + 1)); /*0xd23*/
    n16 = *(_BYTE *)sub_1E30(v12 | v10); /*0xd30*/
    if ( n0x1000 >= 0x1000 ) /*0xd38*/
      break; /*0xd38*/
    ++n0x1000; /*0xd3a*/
  }
  if ( n16 != 16 ) /*0xd43*/
    return 0; /*0xd43*/
LABEL_7:
  v13 = (unsigned __int16 *)sub_1E30((v10 + 18LL) | (((32LL * a1) | a2 & 0x1F) << 15)); /*0xd45*/
  *a4 = sub_2618(v13) & 0xF; /*0xd7b*/
  v14 = (unsigned __int16 *)sub_1E30((v10 + 18LL) | (((32LL * a1) | a2 & 0x1F) << 15)); /*0xd7e*/
  *a5 = ((unsigned __int16)sub_2618(v14) >> 4) & 0x3F; /*0xd96*/
  return 0; /*0xda9*/
}

// Function: SmbiosType9SlotUpdateHelper @ 0xdb4 (0x24d bytes)
// Index: 12/45

__int64 __fastcall SmbiosType9SlotUpdateHelper(
        char a1,
        char a2,
        unsigned __int8 a3,
        char a4,
        char n16,
        __int16 a6,
        unsigned __int8 a7,
        char *Slot9)
{
  char v8; // r12
  unsigned __int8 v9; // bp
  char v10; // r15
  char v11; // si
  char v12; // r13
  __int64 v13; // rbx
  unsigned __int16 *v14; // rax
  unsigned __int8 v15; // r15
  unsigned __int8 *v16; // rax
  unsigned __int8 v17; // bl
  char v18; // di
  __int64 v19; // r14
  unsigned __int16 *v20; // rax
  unsigned __int8 n0x20; // bl
  char v22; // di
  unsigned __int16 *v23; // rax
  unsigned __int64 v24; // rdi
  __int64 v25; // rcx
  char *buf; // rax
  char *buf_1; // rbx
  char n13; // al
  char *Slot9_1; // rdx
  __int64 result; // rax

  v8 = -1; /*0xdde*/
  v9 = a3; /*0xde9*/
  v10 = a2; /*0xdf0*/
  v11 = -1; /*0xdf6*/
  v12 = 0; /*0xdfc*/
  v13 = ((32 * (unsigned __int8)a6) | (a7 >> 3)) << 15; /*0xe06*/
  v14 = (unsigned __int16 *)sub_1E30(v13); /*0xe09*/
  if ( (unsigned __int16)sub_2618(v14) != 0xFFFF ) /*0xe20*/
  {
    v15 = *(_BYTE *)sub_1E30((unsigned int)v13 | 0x19LL); /*0xe38*/
    v16 = (unsigned __int8 *)sub_1E30(v13 | 0x1A); /*0xe3b*/
    v17 = v15; /*0xe40*/
    a7 = *v16; /*0xe45*/
    if ( v15 > a7 ) /*0xe4f*/
      goto LABEL_11; /*0xe4f*/
    do /*0xeb6*/
    {
      v18 = 0; /*0xe51*/
      while ( 1 ) /*0xe68*/
      {
        v19 = ((32 * v17) | v18 & 0x1Fu) << 15; /*0xe68*/
        v20 = (unsigned __int16 *)sub_1E30(v19); /*0xe6b*/
        if ( (unsigned __int16)sub_2618(v20) != 0xFFFF && (*(_BYTE *)sub_1E30(v19 | 0xE) & 0x7F) == 0 ) /*0xe93*/
          break; /*0xe93*/
        if ( (unsigned __int8)++v18 >= 0x20u ) /*0xe9c*/
          goto LABEL_9; /*0xe9c*/
      }
      v8 = v17; /*0xea3*/
      v11 = 8 * v18; /*0xea6*/
      v12 = 1; /*0xeaa*/
LABEL_9:
      ++v17; /*0xead*/
    }
    while ( v17 <= a7 ); /*0xeb6*/
    if ( !v12 ) /*0xebb*/
    {
LABEL_11:
      n0x20 = 0; /*0xec7*/
      v22 = 0; /*0xecd*/
      do /*0xf01*/
      {
        v23 = (unsigned __int16 *)sub_1E30(((32LL * v15) | v22 & 0x1F) << 15); /*0xedc*/
        if ( (unsigned __int16)sub_2618(v23) != 0xFFFF ) /*0xeed*/
        {
          v8 = v15; /*0xef2*/
          v11 = 8 * n0x20; /*0xef5*/
        }
        ++n0x20; /*0xef9*/
        ++v22; /*0xefb*/
      }
      while ( n0x20 < 0x20u ); /*0xf01*/
    }
    v10 = a2; /*0xf03*/
    v9 = a3; /*0xf08*/
  }
  v24 = sub_1858(Slot9); /*0xf1d*/
  buf = (char *)sub_1B18(v25, v24 + 19); /*0xf24*/
  buf_1 = buf; /*0xf29*/
  if ( buf ) /*0xf2f*/
    buf_1 = sub_19B4(buf, v24 + 19); /*0xf3d*/
  buf_1[11] |= 4u; /*0xf44*/
  buf_1[12] |= 1u; /*0xf48*/
  buf_1[5] = a1; /*0xf53*/
  *(_WORD *)(buf_1 + 9) = v9; /*0xf5a*/
  *(_DWORD *)buf_1 = -61175; /*0xf5e*/
  buf_1[4] = 1; /*0xf64*/
  buf_1[8] = v10; /*0xf68*/
  buf_1[15] = v8; /*0xf6c*/
  buf_1[16] = v11; /*0xf70*/
  if ( n16 == 4 ) /*0xf77*/
  {
    buf_1[6] = 10; /*0xf96*/
  }
  else if ( n16 == 8 ) /*0xf81*/
  {
    buf_1[6] = 11; /*0xf91*/
  }
  else
  {
    n13 = 13; /*0xf86*/
    if ( n16 != 16 ) /*0xf89*/
      n13 = 11; /*0xf89*/
    buf_1[6] = n13; /*0xf8c*/
  }
  Slot9_1 = Slot9; /*0xfa6*/
  buf_1[7] = (a4 != 0) + 3; /*0xfb3*/
  sub_17B4((__int64)(buf_1 + 17), Slot9_1); /*0xfb6*/
  a6 = -2; /*0xfc8*/
  result = (*(__int64 (__fastcall **)(__int64, _QWORD, __int16 *, char *))qword_3D78)(qword_3D78, 0, &a6, buf_1); /*0xfdf*/
  if ( result >= 0 ) /*0xfe4*/
  {
    sub_1B48((__int64)buf_1); /*0xfe9*/
    return 0; /*0xfee*/
  }
  return result; /*0xff0*/
}

// Function: CrbDriverEntryPoint @ 0x1004 (0x3d5 bytes)
// Index: 13/45

__int64 __fastcall CrbDriverEntryPoint(__int64 a1)
{
  __int64 result; // rax
  __int64 v3; // rdx
  __int64 v4; // rcx
  __int64 v5; // r8
  char v6; // r9
  char v7; // di
  char v8; // bl
  __int64 v9; // rdx
  char v10; // r8
  __int64 v11; // rcx
  char n10; // al
  __int64 v13; // rcx
  unsigned __int8 n2; // r8
  __int64 v15; // rcx
  char *Slot9; // rax
  __int64 v17; // rcx
  char n2_1; // al
  __int16 v19; // [rsp+28h] [rbp-28h]
  __int16 v20; // [rsp+28h] [rbp-28h]
  __int16 v21; // [rsp+28h] [rbp-28h]
  __int16 v22; // [rsp+28h] [rbp-28h]
  __int16 v23; // [rsp+28h] [rbp-28h]
  char v24; // [rsp+40h] [rbp-10h] BYREF
  unsigned __int8 v25; // [rsp+41h] [rbp-Fh] BYREF
  char v26[2]; // [rsp+42h] [rbp-Eh] BYREF
  __int16 buf__1; // [rsp+44h] [rbp-Ch] BYREF
  __int16 buf[2]; // [rsp+48h] [rbp-8h] BYREF
  __int16 buf_; // [rsp+4Ch] [rbp-4h] BYREF
  int v30; // [rsp+80h] [rbp+30h] BYREF
  char v31; // [rsp+88h] [rbp+38h] BYREF

  buf[0] = 0; /*0x101f*/
  buf_ = 0; /*0x1023*/
  buf__1 = 0; /*0x1027*/
  v24 = 0; /*0x102b*/
  v31 = 0; /*0x102f*/
  LOBYTE(v30) = 0; /*0x1033*/
  v26[0] = 0; /*0x1037*/
  v25 = 0; /*0x103b*/
  if ( !qword_3D78 ) /*0x103f*/
    return 0x8000000000000003uLL; /*0x104b*/
  result = (*(__int64 (__fastcall **)(void *, _QWORD, __int64 *))(BootServices + 320))(&unk_38B0, 0, &qword_3D80); /*0x1067*/
  if ( result >= 0 ) /*0x1070*/
  {
    sub_20E0(buf, &buf_, &buf__1); /*0x1082*/
    (*(void (__fastcall **)(__int64))(BootServices + 112))(a1); /*0x1091*/
    if ( (sub_1E6C((unsigned __int8 *)&v31, &v30, &v24) & 0x8000000000000000uLL) == 0LL ) /*0x10a8*/
    {
      if ( v24 ) /*0x10ae*/
      {
        v7 = v30; /*0x10d9*/
        v8 = v31; /*0x10e1*/
        PciConfigBitParse(v31, v30, v5, v26, &v25); /*0x10f2*/
        sub_B7C(166, v9, v10, v26[0], v25, v8, v7); /*0x110d*/
      }
      else
      {
        sub_B7C( /*0x10d7*/
          181,
          v3,
          v5,
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8091LL),
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8007LL),
          v31,
          v30);
      }
    }
    sub_23E4(v4, &v30, v5, v6); /*0x1116*/
    n10 = sub_21FC(v11); /*0x111b*/
    if ( v30 == 1 ) /*0x1124*/
    {
      if ( !n10 ) /*0x112c*/
      {
        LOBYTE(v19) = buf[0]; /*0x1158*/
        SmbiosType9SlotUpdateHelper( /*0x1168*/
          182,
          4,
          1u,
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8085LL),
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8001LL),
          v19,
          0,
          "Slot1");
        LOBYTE(v20) = buf__1; /*0x1197*/
        SmbiosType9SlotUpdateHelper( /*0x11a7*/
          182,
          4,
          2u,
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8093LL),
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8009LL),
          v20,
          0,
          "Slot2");
      }
      if ( (unsigned __int8)sub_2268(v13) == 1 ) /*0x11b3*/
      {
        LOBYTE(v19) = HIBYTE(buf_); /*0x11de*/
        SmbiosType9SlotUpdateHelper( /*0x11ec*/
          182,
          4,
          3u,
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8110LL),
          *(_BYTE *)(*(_QWORD *)qword_3D80 + 8026LL),
          v19,
          0,
          "Slot3");
      }
      return 0; /*0x13ca*/
    }
    if ( n10 == 8 ) /*0x11f3*/
    {
      LOBYTE(v19) = buf__1; /*0x121f*/
      SmbiosType9SlotUpdateHelper( /*0x122f*/
        182,
        4,
        1u,
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8095LL),
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8011LL),
        v19,
        0x10u,
        "Slot1");
      n2 = 2; /*0x123b*/
      v15 = *(_QWORD *)qword_3D80; /*0x123e*/
      Slot9 = "Slot2"; /*0x1241*/
    }
    else
    {
      if ( n10 != 10 ) /*0x124c*/
        goto LABEL_18; /*0x124c*/
      n2 = 1; /*0x1255*/
      v15 = *(_QWORD *)qword_3D80; /*0x1258*/
      Slot9 = "Slot1"; /*0x125b*/
    }
    LOBYTE(v19) = buf__1; /*0x1278*/
    SmbiosType9SlotUpdateHelper(182, 4, n2, *(_BYTE *)(v15 + 8093), *(_BYTE *)(v15 + 8009), v19, 0, Slot9); /*0x1288*/
    LOBYTE(v21) = buf[0]; /*0x12b7*/
    SmbiosType9SlotUpdateHelper( /*0x12c7*/
      182,
      4,
      3u,
      *(_BYTE *)(*(_QWORD *)qword_3D80 + 8085LL),
      *(_BYTE *)(*(_QWORD *)qword_3D80 + 8001LL),
      v21,
      0,
      "Slot3");
LABEL_18:
    LOBYTE(v19) = buf[0]; /*0x12cc*/
    SmbiosType9SlotUpdateHelper( /*0x1306*/
      181,
      3,
      4u,
      *(_BYTE *)(*(_QWORD *)qword_3D80 + 8087LL),
      *(_BYTE *)(*(_QWORD *)qword_3D80 + 8003LL),
      v19,
      0x10u,
      "Slot4");
    n2_1 = sub_2268(v17); /*0x130b*/
    if ( n2_1 == 4 ) /*0x1312*/
    {
      LOBYTE(v22) = HIBYTE(buf_); /*0x133c*/
      SmbiosType9SlotUpdateHelper( /*0x1346*/
        182,
        4,
        5u,
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8110LL),
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8026LL),
        v22,
        0,
        "Slot5");
    }
    else if ( n2_1 == 2 ) /*0x134a*/
    {
      LOBYTE(v22) = HIBYTE(buf_); /*0x1376*/
      SmbiosType9SlotUpdateHelper( /*0x1386*/
        182,
        4,
        5u,
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8110LL),
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8026LL),
        v22,
        0,
        "Slot5");
      LOBYTE(v23) = HIBYTE(buf_); /*0x13b3*/
      SmbiosType9SlotUpdateHelper( /*0x13c5*/
        182,
        4,
        6u,
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8112LL),
        *(_BYTE *)(*(_QWORD *)qword_3D80 + 8028LL),
        v23,
        0x10u,
        "Slot6");
    }
    return 0; /*0x1346*/
  }
  return result; /*0x13d1*/
}

// Function: SmbiosType9TableUpdate @ 0x13dc (0x27c bytes)
// Index: 14/45

__int64 __fastcall SmbiosType9TableUpdate(__int64 a1, __int64 a2)
{
  unsigned __int8 n8; // di
  __int64 result; // rax
  __int64 v4; // rbx
  __int64 v5; // rdx
  __int64 v6; // r10
  unsigned __int8 v7; // r9
  unsigned __int8 v8; // r8
  int v9; // eax
  __int64 v10; // rdx
  unsigned __int8 v11; // cl
  _QWORD v12[9]; // [rsp+30h] [rbp-48h]
  __int64 v13; // [rsp+B0h] [rbp+38h] BYREF
  __int64 v14; // [rsp+B8h] [rbp+40h] BYREF
  __int64 v15; // [rsp+C0h] [rbp+48h] BYREF
  __int64 v16; // [rsp+C8h] [rbp+50h] BYREF

  v14 = a2; /*0x13dc*/
  v13 = a1; /*0x13e1*/
  LOBYTE(v14) = 9; /*0x13fc*/
  v12[0] = "Slot 1"; /*0x1400*/
  v12[1] = "Slot 2"; /*0x1418*/
  LOWORD(v13) = -2; /*0x1428*/
  v12[2] = "Slot 3"; /*0x142d*/
  v12[3] = "Slot 4"; /*0x1438*/
  v12[4] = "Slot 5"; /*0x1443*/
  v12[5] = "Slot 6"; /*0x144e*/
  v12[6] = "Slot 7"; /*0x1459*/
  v12[7] = "Slot 8"; /*0x1464*/
  sub_172C(64, "UpdateSmbiosType9Table Updating Type 9\n"); /*0x1468*/
  n8 = 0; /*0x146d*/
  while ( 1 ) /*0x1498*/
  {
    result = (*(__int64 (__fastcall **)(__int64, __int64 *, __int64 *, __int64 *, _QWORD))(qword_3D78 + 24))( /*0x1498*/
               qword_3D78,
               &v13,
               &v14,
               &v15,
               0);
    v4 = result; /*0x149b*/
    if ( result < 0 ) /*0x14a1*/
      return result; /*0x1633*/
    if ( (_WORD)v13 == 0xFFFE ) /*0x14ac*/
      goto LABEL_11; /*0x14ac*/
    *(_BYTE *)(v15 + 8) = 4; /*0x14bd*/
    *(_BYTE *)(v15 + 4) = 1; /*0x14c5*/
    *(_BYTE *)(v15 + 11) |= 4u; /*0x14cd*/
    *(_BYTE *)(v15 + 11) &= ~8u; /*0x14d5*/
    *(_BYTE *)(v15 + 12) |= 1u; /*0x14dd*/
    *(_WORD *)(v15 + 9) = n8 + 1; /*0x14e5*/
    v5 = 5LL * n8; /*0x14ed*/
    *(_BYTE *)(v15 + 16) = byte_3960[v5 + 4]; /*0x14fd*/
    *(_BYTE *)(v15 + 5) = byte_3960[v5 + 2]; /*0x150c*/
    *(_BYTE *)(v15 + 6) = byte_3960[v5 + 3]; /*0x151b*/
    v6 = v15; /*0x1525*/
    v7 = byte_3960[v5 + 1]; /*0x1529*/
    v8 = byte_3960[v5]; /*0x1531*/
    if ( !dst ) /*0x1539*/
      return 0x8000000000000006uLL; /*0x164c*/
    v9 = dword_3D14; /*0x153f*/
    if ( !_bittest(&v9, v8) ) /*0x1549*/
      return 0x8000000000000003uLL; /*0x1549*/
    v10 = 8LL * v8; /*0x1559*/
    if ( ((unsigned __int8)(1 << v7) & byte_3D18[v10 + 1]) == 0 ) /*0x1569*/
      return 0x8000000000000003uLL; /*0x164a*/
    *(_BYTE *)(v15 + 13) = byte_3D18[v10]; /*0x1577*/
    *(_BYTE *)(v6 + 15) = byte_3D18[v10 + 2 + v7]; /*0x158a*/
    v11 = *(_BYTE *)sub_1E30( /*0x15ae*/
                      ((*(unsigned __int8 *)(v15 + 16) | ((unsigned __int64)*(unsigned __int8 *)(v15 + 15) << 8)) << 12)
                    | 0x19);
    if ( v11 == 0xFF ) /*0x15b3*/
      *(_BYTE *)(v15 + 7) = 2; /*0x15b9*/
    else
      *(_BYTE *)(v15 + 7) = (*(_DWORD *)sub_1E30((unsigned __int64)v11 << 20) != -1) + 3; /*0x15da*/
    v16 = *(unsigned __int8 *)(v15 + 4); /*0x15ed*/
    ++n8; /*0x160c*/
    v4 = (*(__int64 (__fastcall **)(__int64, __int64 *, __int64 *, _QWORD))(qword_3D78 + 8))( /*0x160f*/
           qword_3D78,
           &v13,
           &v16,
           v12[*(unsigned __int16 *)(v15 + 9) - 1]);
    if ( n8 >= 8u ) /*0x1616*/
    {
LABEL_11:
      sub_172C(64, "UpdateSmbiosType9TableUpdating Type 9 Status %r \n", v4); /*0x161c*/
      return v4; /*0x1630*/
    }
  }
}

// Function: NotifyFunctionCallback @ 0x1658 (0x54 bytes)
// Index: 15/45

__int64 __fastcall NotifyFunctionCallback(__int64 a1)
{
  __int64 result; // rax
  __int64 v3; // rdx
  __int64 v4; // rcx

  DebugLogPrint(64, "UpdateSmbiosTablesUpdating SMBIOS structures \n"); /*0x166d*/
  result = (*(__int64 (__fastcall **)(unsigned int *, _QWORD, __int64 *))(BootServices + 320))( /*0x1689*/
             &dword_3900,
             0,
             &qword_3D78);
  if ( result >= 0 ) /*0x1692*/
  {
    (*(void (__fastcall **)(__int64))(BootServices + 112))(a1); /*0x169e*/
    return SmbiosType9TableUpdate(v4, v3); /*0x16a1*/
  }
  return result; /*0x16a6*/
}

// Function: PciCfgReadByte @ 0x16ac (0x7f bytes)
// Index: 16/45

__int64 PciCfgReadByte()
{
  __int64 result; // rax
  unsigned __int64 n0x10; // rbx
  __int64 v2; // rax
  __int64 v3; // rcx

  result = qword_3CD8; /*0x16b6*/
  if ( !qword_3CD8 ) /*0x16c2*/
  {
    n0x10 = (*(__int64 (__fastcall **)(__int64))(qword_3CC0 + 24))(31); /*0x16db*/
    (*(void (__fastcall **)(unsigned __int64))(qword_3CC0 + 32))(n0x10); /*0x16de*/
    if ( n0x10 <= 0x10 ) /*0x16e5*/
    {
      v2 = (*(__int64 (__fastcall **)(void *, _QWORD, __int64 *))(qword_3CC0 + 320))(&unk_38A0, 0, &qword_3CD8); /*0x1702*/
      v3 = qword_3CD8; /*0x1708*/
      if ( v2 < 0 ) /*0x1712*/
        v3 = 0; /*0x1712*/
      qword_3CD8 = v3; /*0x1716*/
      return v3; /*0x171d*/
    }
    else
    {
      return 0; /*0x16e7*/
    }
  }
  return result; /*0x1725*/
}

// Function: DebugLogPrint @ 0x172c (0x47 bytes)
// Index: 17/45

__int64 DebugLogPrint(__int64 a1, const char *a2, ...)
{
  __int64 result; // rax
  __int64 (__fastcall **v4)(__int64, const char *, __int64 *); // r10
  va_list va; // [rsp+40h] [rbp+18h] BYREF

  va_start(va, a2);
  result = sub_16AC(); /*0x1743*/
  if ( result ) /*0x174e*/
  {
    result = sub_22BC(); /*0x1750*/
    if ( ((unsigned int)result & (unsigned int)a1) != 0 ) /*0x175b*/
      return (*v4)(a1, a2, (__int64 *)va); /*0x176a*/
  }
  return result; /*0x176d*/
}

// Function: AssertCpuDeadLoop @ 0x1774 (0x3e bytes)
// Index: 18/45

__int64 __fastcall AssertCpuDeadLoop(__int64 a1, __int64 a2, __int64 a3)
{
  __int64 result; // rax

  result = sub_16AC(); /*0x178c*/
  if ( result ) /*0x1794*/
    return (*(__int64 (__fastcall **)(__int64, __int64, __int64))(result + 8))(a1, a2, a3); /*0x179f*/
  return result; /*0x17ac*/
}

// Function: AsciiStrCpyS @ 0x17b4 (0xa3 bytes)
// Index: 19/45

RETURN_STATUS __cdecl AsciiStrCpyS(CHAR8 *Destination, UINTN DestMax, const CHAR8 *Source)
{
  CHAR8 *Destination_1; // rbx
  RETURN_STATUS Destination_2; // rax

  Destination_1 = Destination; /*0x17c1*/
  if ( !Destination ) /*0x17c7*/
    AssertCpuDeadLoop( /*0x17dc*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
      971,
      (__int64)"Destination != ((void *) 0)");
  if ( (unsigned __int64)&Destination_1[-DestMax] <= sub_1858((char *)DestMax) ) /*0x17f2*/
    AssertCpuDeadLoop( /*0x1807*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
      976,
      (__int64)"(UINTN)(Destination - Source) > AsciiStrLen (Source)");
  if ( DestMax - (unsigned __int64)Destination_1 <= sub_1858((char *)DestMax) ) /*0x181d*/
    AssertCpuDeadLoop( /*0x1832*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
      977,
      (__int64)"(UINTN)(Source - Destination) > AsciiStrLen (Source)");
  Destination_2 = (RETURN_STATUS)Destination_1; /*0x1837*/
  while ( *(_BYTE *)DestMax ) /*0x1848*/
    *Destination_1++ = *(_BYTE *)DestMax++; /*0x183c*/
  *Destination_1 = 0; /*0x184a*/
  return Destination_2; /*0x1851*/
}

// Function: AsciiStrLen @ 0x1858 (0x6b bytes)
// Index: 20/45

UINTN __cdecl AsciiStrLen(const CHAR8 *String)
{
  const CHAR8 *v1; // rbx
  UINTN i; // rdi

  v1 = String; /*0x1862*/
  if ( !String ) /*0x1868*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\String.c", 1082, (__int64)"String != ((void *) 0)"); /*0x187d*/
  for ( i = 0; *v1; ++i ) /*0x1884*/
  {
    if ( i >= 0xF4240 ) /*0x1890*/
      AssertCpuDeadLoop( /*0x18a5*/
        (__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\String.c",
        1090,
        (__int64)"Length < _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength");
    ++v1; /*0x18aa*/
  }
  return i; /*0x18bd*/
}

// Function: CopyMemWrapper @ 0x18c4 (0x9e bytes)
// Index: 21/45

char *__fastcall CopyMemWrapper(char *dst, char *src, unsigned __int64 n16)
{
  unsigned __int64 v3; // rbp

  v3 = n16 - 1; /*0x18e1*/
  if ( n16 - 1 > -1 - (__int64)dst ) /*0x18f7*/
    AssertCpuDeadLoop( /*0x190a*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
      56,
      (__int64)"(Length - 1) <= (0xFFFFFFFFFFFFFFFFULL - (UINTN)DestinationBuffer)");
  if ( v3 > -1 - (__int64)src ) /*0x1915*/
    AssertCpuDeadLoop( /*0x192a*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\CopyMemWrapper.c",
      57,
      (__int64)"(Length - 1) <= (0xFFFFFFFFFFFFFFFFULL - (UINTN)SourceBuffer)");
  if ( dst == src ) /*0x1932*/
    return dst; /*0x1934*/
  else
    return InternalMemCopyMem(dst, src, n16); /*0x1942*/
}

// Function: SetMemWrapper @ 0x1964 (0x50 bytes)
// Index: 22/45

void *__fastcall SetMemWrapper(void *buf, unsigned __int64 count)
{
  if ( count - 1 > -1 - (__int64)buf ) /*0x1982*/
    AssertCpuDeadLoop( /*0x1997*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\SetMemWrapper.c",
      54,
      (__int64)"(Length - 1) <= (0xFFFFFFFFFFFFFFFFULL - (UINTN)Buffer)");
  return MemCopyForward(buf, count, 255); /*0x19aa*/
}

// Function: SetMem16Wrapper @ 0x19b4 (0x6e bytes)
// Index: 23/45

char *__fastcall SetMem16Wrapper(char *buf, unsigned __int64 a2)
{
  if ( !a2 ) /*0x19c7*/
    return buf; /*0x19c9*/
  if ( !buf ) /*0x19d1*/
    AssertCpuDeadLoop( /*0x19e4*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
      53,
      (__int64)"Buffer != ((void *) 0)");
  if ( a2 > -(__int64)buf ) /*0x19f2*/
    AssertCpuDeadLoop( /*0x1a07*/
      (__int64)"e:\\hs\\MdePkg\\Library\\BaseMemoryLibRepStr\\ZeroMemWrapper.c",
      54,
      (__int64)"Length <= (0xFFFFFFFFFFFFFFFFULL - (UINTN)Buffer + 1)");
  return MemCopyBackward(buf, a2); /*0x1a1c*/
}

// Function: SetMem32Wrapper @ 0x1a24 (0x67 bytes)
// Index: 24/45

bool __fastcall SetMem32Wrapper(__int64 a1, __int64 a2)
{
  __int64 v4; // rsi
  __int64 v5; // rbx
  __int64 v6; // rdi
  __int64 v7; // rax

  v4 = sub_2648(a1); /*0x1a46*/
  v5 = sub_2648(a2); /*0x1a52*/
  v6 = sub_2648(a1 + 8); /*0x1a5e*/
  v7 = sub_2648(a2 + 8); /*0x1a61*/
  return v4 == v5 && v6 == v7; /*0x1a85*/
}

// Function: CompareMemWrapper @ 0x1a8c (0x8c bytes)
// Index: 25/45

__int64 CompareMemWrapper()
{
  __int64 result; // rax
  __int64 v1; // rax

  result = qword_3CE0; /*0x1a90*/
  if ( !qword_3CE0 ) /*0x1a9a*/
  {
    v1 = (*(__int64 (__fastcall **)(void *, _QWORD, __int64 *))(qword_3CC0 + 320))(&unk_38E0, 0, &qword_3CE0); /*0x1ab3*/
    if ( v1 < 0 ) /*0x1abc*/
    {
      DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v1); /*0x1acd*/
      AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\DxePcdLib\\DxePcdLib.c", 78, (__int64)"!EFI_ERROR (Status)"); /*0x1ae5*/
    }
    result = qword_3CE0; /*0x1aea*/
    if ( !qword_3CE0 ) /*0x1af4*/
    {
      AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\DxePcdLib\\DxePcdLib.c", 79, (__int64)"mPcd != ((void *) 0)"); /*0x1b07*/
      return qword_3CE0; /*0x1b0c*/
    }
  }
  return result; /*0x1b13*/
}

// Function: AllocatePoolWrapper @ 0x1b18 (0x2e bytes)
// Index: 26/45

__int64 __fastcall AllocatePoolWrapper(__int64 a1, __int64 a2)
{
  __int64 v2; // rax
  __int64 v3; // rcx
  __int64 v5; // [rsp+40h] [rbp+18h] BYREF

  v2 = (*(__int64 (__fastcall **)(__int64, __int64, __int64 *))(qword_3CC0 + 64))(4, a2, &v5); /*0x1b2d*/
  v3 = v5; /*0x1b30*/
  if ( v2 < 0 ) /*0x1b3a*/
    return 0; /*0x1b3a*/
  return v3; /*0x1b41*/
}

// Function: AllocateZeroPoolWrapper @ 0x1b48 (0x44 bytes)
// Index: 27/45

__int64 __fastcall AllocateZeroPoolWrapper(__int64 buf)
{
  __int64 result; // rax

  result = (*(__int64 (__fastcall **)(__int64))(qword_3CC0 + 72))(buf); /*0x1b53*/
  if ( result < 0 ) /*0x1b59*/
  {
    DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", result); /*0x1b6a*/
    return AssertCpuDeadLoop( /*0x1b82*/
             (__int64)"e:\\hs\\MdePkg\\Library\\UefiMemoryAllocationLib\\MemoryAllocationLib.c",
             819,
             (__int64)"!EFI_ERROR (Status)");
  }
  return result; /*0x1b87*/
}

// Function: DxeServicesTableRegister @ 0x1b8c (0xc4 bytes)
// Index: 28/45

unsigned __int64 __fastcall DxeServicesTableRegister(__int64 a1, _QWORD *a2)
{
  __int64 v4; // rdi
  __int64 v5; // rbx
  __int64 i; // r14

  if ( !a1 ) /*0x1bae*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 97, (__int64)"TableGuid != ((void *) 0)"); /*0x1bc1*/
  if ( !a2 ) /*0x1bc9*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 98, (__int64)"Table != ((void *) 0)"); /*0x1bdc*/
  v4 = qword_3CB8; /*0x1be1*/
  v5 = 0; /*0x1be8*/
  *a2 = 0; /*0x1bea*/
  if ( !*(_QWORD *)(v4 + 104) ) /*0x1bee*/
    return 0x800000000000000EuLL; /*0x1c17*/
  for ( i = 0; !sub_1A24(a1, i + *(_QWORD *)(v4 + 112)); i += 24 ) /*0x1bf4*/
  {
    if ( (unsigned __int64)++v5 >= *(_QWORD *)(v4 + 104) ) /*0x1c15*/
      return 0x800000000000000EuLL; /*0x1c15*/
  }
  *a2 = *(_QWORD *)(*(_QWORD *)(v4 + 112) + 24 * v5 + 16); /*0x1c4b*/
  return 0; /*0x1c35*/
}

// Function: UefiLibCreateProtocolNotifyEvent @ 0x1c50 (0x12a bytes)
// Index: 29/45

__int64 __fastcall UefiLibCreateProtocolNotifyEvent(
        __int64 a1,
        EFI_SYSTEM_TABLE *SystemTable,
        __int64 sub_1658,
        __int64 a4,
        __int64 a5)
{
  __int64 v7; // rax
  __int64 v8; // rax

  if ( !a1 ) /*0x1c74*/
    sub_1774((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 152, (__int64)"ProtocolGuid != ((void *) 0)"); /*0x1c85*/
  if ( !sub_1658 ) /*0x1c8d*/
    sub_1774((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 153, (__int64)"NotifyFunction != ((void *) 0)"); /*0x1c9e*/
  if ( !a5 ) /*0x1ca9*/
    sub_1774((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 154, (__int64)"Registration != ((void *) 0)"); /*0x1cba*/
  v7 = (*(__int64 (__fastcall **)(__int64, __int64, __int64))(qword_3CC0 + 80))(512, 8, sub_1658); /*0x1cdf*/
  if ( v7 < 0 ) /*0x1cea*/
  {
    sub_172C(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v7); /*0x1cf8*/
    sub_1774((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 167, (__int64)"!EFI_ERROR (Status)"); /*0x1d0c*/
  }
  v8 = (*(__int64 (__fastcall **)(__int64, __int64, __int64))(qword_3CC0 + 168))(a1, a4, a5); /*0x1d25*/
  if ( v8 < 0 ) /*0x1d2e*/
  {
    sub_172C(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v8); /*0x1d3d*/
    sub_1774((__int64)"e:\\hs\\MdePkg\\Library\\UefiLib\\UefiLib.c", 179, (__int64)"!EFI_ERROR (Status)"); /*0x1d51*/
  }
  (*(void (__fastcall **)(__int64))(qword_3CC0 + 104))(a4); /*0x1d62*/
  return a4; /*0x1d74*/
}

// Function: SmbiosType9SetSlotId @ 0x1d7c (0x30 bytes)
// Index: 30/45

__int64 SmbiosType9SetSlotId()
{
  _DWORD v1[6]; // [rsp+20h] [rbp-18h] BYREF

  v1[3] = 0; /*0x1d83*/
  v1[1] = 0; /*0x1d8b*/
  v1[2] = 512; /*0x1d8f*/
  v1[0] = 1015808; /*0x1d96*/
  return (*(__int64 (__fastcall **)(_DWORD *))(qword_3CF0 + 24))(v1); /*0x1da7*/
}

// Function: SmbiosType9GetSlotConfig @ 0x1dac (0x82 bytes)
// Index: 31/45

__int64 SmbiosType9GetSlotConfig()
{
  __int64 result; // rax
  signed __int64 v1; // rax

  result = qword_3CF8; /*0x1db0*/
  if ( !qword_3CF8 ) /*0x1dba*/
  {
    v1 = DxeServicesTableRegister((__int64)&unk_3920, &qword_3CF8); /*0x1dca*/
    if ( v1 < 0 ) /*0x1dd2*/
    {
      DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v1); /*0x1de3*/
      AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c", 54, (__int64)"!EFI_ERROR (Status)"); /*0x1dfb*/
    }
    result = qword_3CF8; /*0x1e00*/
    if ( !qword_3CF8 ) /*0x1e0a*/
    {
      AssertCpuDeadLoop( /*0x1e1d*/
        (__int64)"e:\\hs\\MdePkg\\Library\\DxeHobLib\\HobLib.c",
        55,
        (__int64)"mHobList != ((void *) 0)");
      return qword_3CF8; /*0x1e22*/
    }
  }
  return result; /*0x1e29*/
}

// Function: MmioReadHelper @ 0x1e30 (0x3a bytes)
// Index: 32/45

__int64 __fastcall MmioReadHelper(__int64 a1)
{
  if ( (a1 & 0xFFFFFFFFF0000000uLL) != 0 ) /*0x1e40*/
    sub_1774( /*0x1e55*/
      (__int64)"e:\\hs\\MdePkg\\Library\\SmmPciExpressLib\\PciExpressLib.c",
      118,
      (__int64)"((Address) & ~0xfffffff) == 0");
  return a1 + qword_3D00; /*0x1e64*/
}

// Function: SmbiosType9SlotDataValidate @ 0x1e6c (0x274 bytes)
// Index: 33/45

unsigned __int64 __fastcall SmbiosType9SlotDataValidate(unsigned __int8 *a1, _BYTE *a2, _BYTE *a3)
{
  char v5; // si
  unsigned __int16 *v6; // rax
  unsigned __int8 v7; // bl
  unsigned __int8 v8; // r15
  char v9; // di
  unsigned __int8 v11; // r14
  __int64 v12; // r12
  char v13; // bl
  __int64 v14; // r15
  unsigned __int16 *v15; // rax
  unsigned __int16 *v16; // rax
  __int64 v17; // rbx
  unsigned __int8 v18; // di
  char v19; // bl
  unsigned __int8 v20; // [rsp+20h] [rbp-20h]
  __int16 buf_; // [rsp+24h] [rbp-1Ch] BYREF
  _WORD buf_1[2]; // [rsp+28h] [rbp-18h] BYREF
  __int16 buf; // [rsp+2Ch] [rbp-14h] BYREF
  __int64 v24; // [rsp+30h] [rbp-10h]
  unsigned __int8 v27; // [rsp+98h] [rbp+58h]

  buf = 0; /*0x1e8d*/
  buf_ = 0; /*0x1e96*/
  buf_1[0] = 0; /*0x1e9e*/
  v5 = 0; /*0x1eaa*/
  sub_20E0(&buf, &buf_, buf_1); /*0x1eb1*/
  v6 = (unsigned __int16 *)sub_1E30(((unsigned __int64)(unsigned __int8)buf_ << 20) | 0x10000); /*0x1ec3*/
  if ( (unsigned __int16)sub_2618(v6) != 0xFFFF ) /*0x1ed8*/
  {
    v7 = *(_BYTE *)sub_1E30(((unsigned __int64)(unsigned __int8)buf_ << 20) | 0x10019); /*0x1ef2*/
    if ( (unsigned __int8)(v7 - 1) > 0xFDu ) /*0x1ef9*/
      return 0x8000000000000006uLL; /*0x1ef9*/
    v8 = *(_BYTE *)sub_1E30(((unsigned __int64)(unsigned __int8)buf_ << 20) | 0x1001A); /*0x1f13*/
    if ( (unsigned __int8)(v8 - 1) > 0xFDu ) /*0x1f1c*/
      return 0x8000000000000006uLL; /*0x1f8c*/
    if ( v7 <= v8 ) /*0x1f21*/
    {
      do /*0x1f23*/
      {
        v9 = 0; /*0x1f23*/
        while ( *(_BYTE *)sub_1E30((((32LL * v7) | v9 & 0x1F) << 15) | 0xB) != 2 ) /*0x1f4a*/
        {
          if ( (unsigned __int8)++v9 >= 0x20u ) /*0x1f53*/
            goto LABEL_10; /*0x1f53*/
        }
        v5 = 1; /*0x1f5b*/
        *a1 = v7; /*0x1f5e*/
        *a2 = v9; /*0x1f62*/
        *a3 = 0; /*0x1f66*/
LABEL_10:
        if ( v5 == 1 ) /*0x1f6d*/
          return 0; /*0x1f6d*/
      }
      while ( ++v7 <= v8 ); /*0x1f23*/
    }
  }
  v11 = 0; /*0x1f91*/
  v12 = 0; /*0x1f94*/
  v27 = 0; /*0x1f97*/
  v24 = 0; /*0x1f9b*/
  do /*0x20a3*/
  {
    v13 = 0; /*0x1f9f*/
    while ( 1 ) /*0x1fb5*/
    {
      v14 = ((32 * v11) | v13 & 0x1Fu) << 15; /*0x1fb5*/
      v15 = (unsigned __int16 *)sub_1E30(v14); /*0x1fb8*/
      if ( (unsigned __int16)sub_2618(v15) == 0x8086 ) /*0x1fcd*/
      {
        v16 = (unsigned __int16 *)sub_1E30(v14 | 2); /*0x1fd6*/
        if ( (unsigned __int16)sub_2618(v16) == 14277 ) /*0x1feb*/
          break; /*0x1feb*/
      }
      if ( ++v13 == -1 ) /*0x1ff2*/
        goto LABEL_30; /*0x1ff2*/
    }
    v17 = ((32 * v12) | v13 & 0x1F) << 15; /*0x200a*/
    v18 = *(_BYTE *)sub_1E30(v17 | 0x19); /*0x2021*/
    v20 = *(_BYTE *)sub_1E30(v17 | 0x1A); /*0x202b*/
    if ( v18 <= v20 ) /*0x2031*/
    {
      do /*0x2087*/
      {
        v19 = 0; /*0x203b*/
        while ( *(_BYTE *)sub_1E30((((32LL * v18) | v19 & 0x1F) << 15) | 0xB) != 2 ) /*0x2060*/
        {
          if ( (unsigned __int8)++v19 >= 0x20u ) /*0x2067*/
            goto LABEL_27; /*0x2067*/
        }
        *a3 = 1; /*0x206b*/
        v5 = 1; /*0x2070*/
        *a1 = v18; /*0x2073*/
        *a2 = v19; /*0x2076*/
LABEL_27:
        if ( v5 == 1 ) /*0x207e*/
          break; /*0x207e*/
        ++v18; /*0x2080*/
      }
      while ( v18 <= v20 ); /*0x2087*/
      v11 = v27; /*0x2089*/
      v12 = v24; /*0x208d*/
    }
LABEL_30:
    ++v11; /*0x2091*/
    ++v12; /*0x2094*/
    v27 = v11; /*0x2097*/
    v24 = v12; /*0x209b*/
  }
  while ( v11 != 0xFF ); /*0x20a3*/
  if ( v5 ) /*0x20ac*/
    return 0; /*0x1f7d*/
  *a2 = -1; /*0x20b6*/
  *a1 = -1; /*0x20bb*/
  return 0x800000000000000EuLL; /*0x20d0*/
}

// Function: SmbiosType9GetSlotInfo @ 0x20e0 (0x119 bytes)
// Index: 34/45

__int16 __fastcall SmbiosType9GetSlotInfo(void *buf, void *buf_1, void *buf_2)
{
  unsigned __int8 n2; // bp
  unsigned __int8 v7; // si
  __int64 v8; // r14
  UINTN Helper; // rax
  _BYTE *n8214; // rax
  UINTN Address; // rax
  __int64 n2_1; // rbx

  n2 = 0; /*0x20ff*/
  sub_1964(buf, 2u); /*0x210c*/
  sub_1964(buf_1, 2u); /*0x2116*/
  sub_1964(buf_2, 2u); /*0x2120*/
  v7 = 0; /*0x2125*/
  v8 = 0; /*0x2128*/
  do /*0x21d6*/
  {
    Helper = MmioReadHelper((v7 << 20) | 0x42000LL); /*0x213d*/
    LOWORD(n8214) = MmioRead16(Helper); /*0x2145*/
    if ( (_WORD)n8214 == 0x8086 ) /*0x2152*/
    {
      Address = MmioReadHelper((v7 << 20) | 0x42002LL); /*0x215e*/
      LOWORD(n8214) = MmioRead16(Address); /*0x2166*/
      if ( (_WORD)n8214 == 8214 && n2 < 2u ) /*0x2178*/
      {
        n2_1 = n2; /*0x2190*/
        *((_BYTE *)buf + n2) = *(_BYTE *)MmioReadHelper((v8 << 20) | 0x420CD); /*0x21a0*/
        *((_BYTE *)buf_1 + n2) = *(_BYTE *)MmioReadHelper((v8 << 20) | 0x420CE); /*0x21b5*/
        n8214 = (_BYTE *)MmioReadHelper((v8 << 20) | 0x420CF); /*0x21b9*/
        ++n2; /*0x21be*/
        *((_BYTE *)buf_2 + n2_1) = *n8214; /*0x21c8*/
      }
    }
    ++v7; /*0x21cc*/
    ++v8; /*0x21cf*/
  }
  while ( v7 != 0xFF ); /*0x21d6*/
  return (__int16)n8214; /*0x21eb*/
}

// Function: GpioGetPadConfig @ 0x21fc (0x6c bytes)
// Index: 35/45

char __fastcall GpioGetPadConfig(UINTN Address)
{
  UINTN Address_1; // rcx
  UINTN Address_2; // rcx
  UINTN Address_3; // rcx
  char v5; // [rsp+30h] [rbp+8h]
  char v6; // [rsp+38h] [rbp+10h]
  char v7; // [rsp+40h] [rbp+18h]
  char v8; // [rsp+48h] [rbp+20h]

  MmioWrite16(Address, 0x420u); /*0x220a*/
  MmioWrite16(Address_1, 0x418u); /*0x2219*/
  MmioWrite16(Address_2, 0x410u); /*0x2228*/
  MmioWrite16(Address_3, 0x408u); /*0x2237*/
  return v8 & 2 | ((v7 & 2) != 0) | (2 * (v6 & 2 | (2 * (v5 & 2)))); /*0x2263*/
}

// Function: GpioSetPadConfig @ 0x2268 (0x52 bytes)
// Index: 36/45

__int64 __fastcall GpioSetPadConfig(UINTN Address)
{
  UINTN Address_1; // rcx
  UINTN Address_2; // rcx
  __int64 result; // rax
  unsigned int v4; // [rsp+30h] [rbp+8h]
  char v5; // [rsp+38h] [rbp+10h]
  char v6; // [rsp+40h] [rbp+18h]

  MmioWrite16(Address, 0x438u); /*0x2276*/
  MmioWrite16(Address_1, 0x430u); /*0x2285*/
  MmioWrite16(Address_2, 0x428u); /*0x2294*/
  result = v4 >> 1; /*0x22a4*/
  LOBYTE(result) = v6 & 2 | (2 * (v5 & 2)) | ((v4 & 2) != 0); /*0x22b3*/
  return result; /*0x22b5*/
}

// Function: GpioCheckPadOverride @ 0x22bc (0x4e bytes)
// Index: 37/45

__int64 GpioCheckPadOverride()
{
  unsigned __int8 v0; // al
  char n3_1; // al
  char n3; // cl
  __int64 result; // rax

  v0 = __inbyte(0x70u); /*0x22c1*/
  __outbyte(0x70u, v0 & 0x80 | 0x4B); /*0x22c6*/
  n3_1 = __inbyte(0x71u); /*0x22cc*/
  n3 = n3_1; /*0x22cd*/
  if ( (unsigned __int8)n3_1 > 3u ) /*0x22d4*/
  {
    n3 = n3; /*0x22d6*/
    if ( !n3 ) /*0x22de*/
      n3 = MEMORY[0xFDAF0490] & 2 | 1; /*0x22ea*/
  }
  if ( (unsigned __int8)(n3 - 1) > 0xFDu ) /*0x22f4*/
    return 0; /*0x2307*/
  result = 2147483718LL; /*0x22f9*/
  if ( n3 == 1 ) /*0x2303*/
    return 2147483652LL; /*0x2303*/
  return result; /*0x2306*/
}

// Function: GpioPadCfgValidate @ 0x230c (0xd7 bytes)
// Index: 38/45

unsigned __int64 __fastcall GpioPadCfgValidate(__int64 a1, __int64 a2, __int64 a3, char a4, int *a5)
{
  _DWORD *v6; // rax
  __int64 v7; // rcx
  _DWORD *v8; // rbx
  unsigned __int64 p_n6[3]; // [rsp+20h] [rbp-18h] BYREF
  int v10; // [rsp+58h] [rbp+20h] BYREF

  LOBYTE(v10) = a4; /*0x230c*/
  if ( (unsigned int)sub_2580() != 1 )
  {
    DebugLogPrint(0x80000000LL, "GPIO ERROR: Incorrect GpioPad define used on this chipset (Group=%d, Pad=%d)!\n", 6, 0);
    return 0x8000000000000003uLL; /*0x2344*/
  }
  v6 = sub_24E8(p_n6); /*0x234e*/
  v8 = v6; /*0x2359*/
  if ( p_n6[0] <= 6 )
  {
    DebugLogPrint(0x80000000LL, "GPIO ERROR: Group argument (%d) exceeds GPIO group range\n", 6);
    return 0x8000000000000002uLL; /*0x237f*/
  }
  if ( !v6[104] )
  {
    DebugLogPrint(0x80000000LL, "GPIO ERROR: Pin number (%d) exceeds possible range for this group\n", 0);
    return 0x8000000000000002uLL; /*0x2394*/
  }
  sub_2440(v7, &v10); /*0x239b*/
  if ( v10 )
  {
    DebugLogPrint(0x80000000LL, "GPIO ERROR: Accessing pad not owned by host (Group=%d, Pad=%d)!\n", 6, 0);
    return 0x8000000000000003uLL; /*0x23ae*/
  }
  *a5 = *(_DWORD *)(*((unsigned __int16 *)v8 + 206) | ((*((unsigned __int8 *)v8 + 360) | 0xFD00LL) << 16)) & 2; /*0x23d9*/
  return 0; /*0x23dd*/
}

// Function: GpioGetCommunity @ 0x23e4 (0x5b bytes)
// Index: 39/45

signed __int64 __fastcall GpioGetCommunity(__int64 a1, int *a2, __int64 a3, char a4)
{
  signed __int64 v5; // rax
  signed __int64 v6; // rdi

  v5 = GpioPadCfgValidate(a1, (__int64)a2, a3, a4, a2); /*0x23f6*/
  v6 = v5; /*0x23fb*/
  if ( v5 < 0 ) /*0x2401*/
  {
    DebugLogPrint(0x80000000LL, "\nASSERT_EFI_ERROR (Status = %r)\n", v5); /*0x2412*/
    AssertCpuDeadLoop( /*0x242a*/
      (__int64)"e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
      935,
      (__int64)"!EFI_ERROR (Status)");
  }
  *a2 = (unsigned int)*a2 >> 1; /*0x242f*/
  return v6; /*0x2439*/
}

// Function: GpioGroupCheck @ 0x2440 (0xa5 bytes)
// Index: 40/45

unsigned __int64 __fastcall GpioGroupCheck(__int64 a1, int *a2)
{
  _DWORD *v3; // rax
  __int64 n1389; // rdx
  unsigned __int64 p_n6; // [rsp+40h] [rbp+18h] BYREF

  v3 = sub_24E8(&p_n6); /*0x244e*/
  if ( p_n6 <= 6 )
  {
    DebugLogPrint(0x80000000LL, "GPIO ERROR: Group argument (%d) exceeds GPIO group range\n", 6);
    n1389 = 1389; /*0x2472*/
LABEL_3:
    AssertCpuDeadLoop( /*0x2477*/
      (__int64)"e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmGpioLib\\GpioLib.c",
      n1389,
      (__int64)"((BOOLEAN)(0==1))");
    return 0x8000000000000002uLL; /*0x2494*/
  }
  if ( !v3[104] )
  {
    DebugLogPrint(0x80000000LL, "GPIO ERROR: Pin number (%d) exceeds possible range for this group\n", 0);
    n1389 = 1398; /*0x24b3*/
    goto LABEL_3; /*0x24b8*/
  }
  *a2 = *(_DWORD *)(*((unsigned __int16 *)v3 + 182) | ((*((unsigned __int8 *)v3 + 360) | 0xFD00LL) << 16)) & 3; /*0x24db*/
  return 0; /*0x24df*/
}

// Function: GpioGetPadCfgBase @ 0x24e8 (0x97 bytes)
// Index: 41/45

void *__fastcall GpioGetPadCfgBase(unsigned __int64 *p_n6)
{
  int n2; // ebx
  __int64 v3; // rax
  UINT16 v4; // ax

  n2 = n2; /*0x24f2*/
  if ( n2 == 2 )
  {
    v3 = SmbiosType9SetSlotId(); /*0x2500*/
    v4 = MmioRead16(v3 + 2); /*0x2509*/
    if ( ((v4 + 24128) & 0xFF70) != 0 )
    {
      DebugLogPrint(0x80000000LL, "Unsupported PCH SKU, LpcDeviceId: 0x%04x!\n", v4);
      AssertCpuDeadLoop( /*0x2547*/
        (__int64)"e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchInfoLib\\PchInfoLib.c",
        290,
        (__int64)"((BOOLEAN)(0==1))");
    }
    else
    {
      n2 = 1; /*0x254e*/
    }
    n2 = n2; /*0x2553*/
  }
  if ( n2 == 1 ) /*0x255c*/
  {
    *p_n6 = 13; /*0x255e*/
    return &unk_3990; /*0x2565*/
  }
  else
  {
    *p_n6 = 0; /*0x256e*/
    return 0; /*0x2572*/
  }
}

// Function: GpioGetChipsetId @ 0x2580 (0x97 bytes)
// Index: 42/45

__int64 GpioGetChipsetId()
{
  __int64 n3; // rax
  unsigned int n3_1; // ebx
  __int64 v2; // rax
  UINT16 v3; // ax
  int v4; // edx
  int n335; // eax

  n3 = (unsigned int)n3_0; /*0x2586*/
  n3_1 = 3; /*0x258c*/
  if ( n3_0 == 3 )
  {
    v2 = SmbiosType9SetSlotId(); /*0x2595*/
    v3 = MmioRead16(v2 + 2); /*0x259e*/
    v4 = v3; /*0x25a3*/
    if ( ((v3 + 24128) & 0xFF70) != 0 )
    {
      if ( (unsigned __int16)(v3 + 25280) <= 8u && (n335 = 335, _bittest(&n335, v4 + 25280)) )
      {
        n3_1 = 2; /*0x25ce*/
      }
      else
      {
        DebugLogPrint(0x80000000LL, "Unsupported PCH SKU, LpcDeviceId: 0x%04x!\n", (unsigned __int16)v4);
        AssertCpuDeadLoop( /*0x25fd*/
          (__int64)"e:\\hs\\PurleySktPkg\\SouthClusterLbg\\Library\\PeiDxeSmmPchInfoLib\\PchInfoLib.c",
          252,
          (__int64)"((BOOLEAN)(0==1))");
      }
    }
    else
    {
      n3_1 = 1; /*0x2604*/
    }
    n3_0 = n3_1; /*0x2609*/
    return n3_1; /*0x260f*/
  }
  return n3; /*0x2611*/
}

// Function: MmioRead16 @ 0x2618 (0x2f bytes)
// Index: 43/45

UINT16 __cdecl MmioRead16(UINTN Address)
{
  if ( (Address & 1) != 0 ) /*0x2624*/
    sub_1774((__int64)"e:\\hs\\MdePkg\\Library\\BaseIoLibIntrinsic\\IoLib.c", 151, (__int64)"(Address & 1) == 0"); /*0x2639*/
  return *(_WORD *)Address; /*0x2641*/
}

// Function: MmioGetBaseAddr @ 0x2648 (0x2f bytes)
// Index: 44/45

__int64 __fastcall MmioGetBaseAddr(__int64 a1)
{
  if ( !a1 ) /*0x2654*/
    AssertCpuDeadLoop((__int64)"e:\\hs\\MdePkg\\Library\\BaseLib\\Unaligned.c", 192, (__int64)"Buffer != ((void *) 0)"); /*0x2669*/
  return *(_QWORD *)a1; /*0x2671*/
}

// Function: MmioWrite16 @ 0x2678 (0x6e bytes)
// Index: 45/45

UINT16 __cdecl MmioWrite16(UINTN Address, UINT16 Value)
{
  _DWORD *v2; // r8
  _DWORD *v4; // rbx
  unsigned __int8 *v5; // rax
  unsigned __int64 p_n6; // [rsp+48h] [rbp+20h] BYREF

  v4 = v2; /*0x2689*/
  v5 = (unsigned __int8 *)sub_24E8(&p_n6); /*0x268c*/
  if ( p_n6 > 6 ) /*0x2697*/
  {
    *v4 = *(_DWORD *)(Value | ((v5[360] | 0xFD00LL) << 16)); /*0x26d7*/
    return 0; /*0x26d9*/
  }
  else
  {
    AssertCpuDeadLoop( /*0x26ac*/
      (__int64)"e:\\hs\\PurleySktPkg\\SouthClusterLbg\\LibraryPrivate\\PeiDxeSmmGpioPrivateLib\\GpioPrivateLib.c",
      59,
      (__int64)"((BOOLEAN)(0==1))");
    return 2; /*0x26b1*/
  }
}