// InstallSetupVariables - decompiled from Platform.efi
__int64 __fastcall InstallSetupVariables(void *Buffer, __int64 a2)
{
  __int64 Protocol; // rax
  void *Buffer_2; // rbx
  __int64 v4; // rax
  __int64 Uint32; // rax
  __int64 v6; // rdx
  __int64 v7; // rcx
  __int64 v8; // r8
  __int64 v9; // r9
  __int64 v10; // rax
  void *Buffer_3; // rax
  __int64 v12; // rax
  __int64 v13; // rax
  __int64 v14; // rax
  __int64 v15; // rax
  __int64 v16; // rax
  _BYTE v18[24]; // [rsp+30h] [rbp-18h] BYREF
  void *Buffer_1; // [rsp+80h] [rbp+38h] BYREF
  __int64 v20; // [rsp+88h] [rbp+40h] BYREF
  __int64 Buffer_4; // [rsp+90h] [rbp+48h] BYREF
  __int64 (__fastcall **v22)(_QWORD, __int64 *); // [rsp+98h] [rbp+50h] BYREF

  v20 = a2; /*0x8e84*/
  Buffer_1 = Buffer; /*0x8e89*/
  Protocol = LocateProtocol(); /*0x8e9d*/
  Buffer_2 = (void *)(*(__int64 (__fastcall **)(__int64))(Protocol + 32))(137); /*0x8ebe*/
  if ( !Buffer_2 ) /*0x8ecb*/
  {
    Buffer_4 = 0xFFFFFFFFLL; /*0x8ed9*/
    v4 = (*(__int64 (__fastcall **)(__int64, _QWORD, __int64, __int64 *))(BootServices + 40))(1, 0, 1, &Buffer_4); /*0x8eed*/
    if ( v4 < 0 ) /*0x8ef3*/
    {
      DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", v4); /*0x8efe*/
      Assert( /*0x8f0e*/
        (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
        586,
        (__int64)"!EFI_ERROR (Status)");
    }
    Buffer_2 = (void *)Buffer_4; /*0x8f13*/
    byte_FF38 = 1; /*0x8f1f*/
    Uint32 = GetUint32(137, Buffer_4); /*0x8f26*/
    if ( Uint32 < 0 ) /*0x8f2e*/
    {
      DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", Uint32); /*0x8f39*/
      Assert( /*0x8f49*/
        (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
        591,
        (__int64)"!EFI_ERROR (Status)");
    }
    ZeroMem(Buffer_2, 0x20u); /*0x8f56*/
    qword_FF40 = DevicePathUtilities(v7, v6, v8, v9, (__int64)v18); /*0x8f69*/
    if ( !qword_FF40 ) /*0x8f73*/
      Assert( /*0x8f84*/
        (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
        603,
        (__int64)"mEventDxeSmmReadyToLock != ((void *) 0)");
  }
  ::Buffer = (__int64)Buffer_2; /*0x8f96*/
  if ( (*(__int64 (__fastcall **)(void *, _QWORD, __int64 (__fastcall ***)(_QWORD, __int64 *)))(BootServices + 320))( /*0x8fe7*/
         &unk_FBF0,
         0,
         &v22) >= 0
    && (*v22)(v22, &v20) >= 0
    && (_BYTE)v20
    && v22[1](v22, &qword_FF48) >= 0 )
  {
    v10 = LocateProtocol(); /*0x8fed*/
    Buffer_3 = (void *)(*(__int64 (__fastcall **)(__int64))(v10 + 32))(138); /*0x8ff9*/
    Buffer_1 = Buffer_3; /*0x8ffc*/
    if ( !Buffer_3 ) /*0x9003*/
    {
      v12 = (*(__int64 (__fastcall **)(__int64, __int64, void **))(qword_FF48 + 80))(6, 32, &Buffer_1); /*0x901a*/
      if ( v12 < 0 ) /*0x9020*/
      {
        DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", v12); /*0x902b*/
        Assert( /*0x903b*/
          (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
          639,
          (__int64)"!EFI_ERROR (Status)");
      }
      byte_FF60 = 1; /*0x9047*/
      v13 = GetUint32(138, (__int64)Buffer_1); /*0x904e*/
      if ( v13 < 0 ) /*0x9056*/
      {
        DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", v13); /*0x9061*/
        Assert( /*0x9071*/
          (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
          643,
          (__int64)"!EFI_ERROR (Status)");
      }
      ZeroMem(Buffer_1, 0x20u); /*0x907f*/
      v14 = (*(__int64 (__fastcall **)(void *, __int64 (*)(), __int64 *))(qword_FF48 + 192))( /*0x90a0*/
              &unk_FA70,
              SetupVarMigrate,
              &qword_FF50);
      if ( v14 < 0 ) /*0x90a9*/
      {
        DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", v14); /*0x90b4*/
        Assert( /*0x90c4*/
          (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
          654,
          (__int64)"!EFI_ERROR (Status)");
      }
      v15 = (*(__int64 (__fastcall **)(void *, __int64 (*)(), __int64 *))(qword_FF48 + 192))( /*0x90e5*/
              &unk_FA40,
              SetupVarMigrate,
              &qword_FF30);
      if ( v15 < 0 ) /*0x90ee*/
      {
        DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", v15); /*0x90f9*/
        Assert( /*0x9109*/
          (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
          661,
          (__int64)"!EFI_ERROR (Status)");
      }
      Buffer_3 = Buffer_1; /*0x910e*/
    }
    Buffer_0 = (__int64)Buffer_3; /*0x9112*/
    v16 = (*(__int64 (__fastcall **)(void *, __int64 (*)(), __int64 *))(qword_FF48 + 192))( /*0x9135*/
            &unk_FB70,
            SetupDataMigrate,
            &qword_FF58);
    if ( v16 < 0 ) /*0x913e*/
    {
      DebugPrint(0x80000000, "\nASSERT_EFI_ERROR (Status = %r)\n", v16); /*0x9149*/
      Assert( /*0x9159*/
        (__int64)"e:\\hs\\MdeModulePkg\\Library\\PiDxeS3BootScriptLib\\BootScriptSave.c",
        673,
        (__int64)"!EFI_ERROR (Status)");
    }
  }
  return 0; /*0x9160*/
}
