KiUpdateStibpPairing

__int64 __fastcall KiUpdateStibpPairing(__int64 a1){
  struct _KPRCB *CurrentPrcb; 
  unsigned int v2; 
  int v3; 
  int v4; 
  unsigned int v5; 
  int v6; 
  __int64 v7; 
  __int64 v8; 
  unsigned int v9; 
  int v10; 
  char v11; 
  char v12; 
  char v13; 
  signed __int16 v14; 
  signed __int16 v15; 
  signed __int16 v16; 
  signed __int16 v17; 
  signed __int16 v18; 
  __int64 v19; 
  int v20; 
  signed __int16 v21; 
  signed __int16 v22; 
  signed __int16 v23; 
  signed __int16 v24; 
  signed __int16 v25; 
  signed __int16 v26; 
  signed __int16 v27; 
  char v28; 
  __int64 result; 
  int v30; 
  CurrentPrcb = KeGetCurrentPrcb();
  v2 = 0;
  v3 = 0;
  v4 = 1;
  if( !a1 )
  {
    v4 = 0;
    a1 = *((_QWORD *)KeGetCurrentThread() + 68);
  }
  v5 = *(_DWORD *)(a1 + 2172);
  v6 = 0;
  v7 = *(_QWORD *)(a1 + 2528);
  v8 = *((_QWORD *)CurrentPrcb + 1462);
  v9 = v5 >> 23;
  v10 = v5 & 0xC00000;
  v30 = v9 & 1;
  if( v4 )
  {
    if( ((*(_DWORD *)(a1 + 2172) >> 22) & 1) != 0 && *((_QWORD *)CurrentPrcb + 30) )
    {
      __writemsr(0x49u, 1ui64);
      if( (KiSpeculationFeatures & 8) != 0 )
      {
        v12 = *((_BYTE *)CurrentPrcb + 248);
      }
      else
      {
        KiFlushCurrentRsb();
        v13 = *((_BYTE *)CurrentPrcb + 248);
        *((_BYTE *)CurrentPrcb + 1746) &= ~0x40u;
        v12 = v13 & 0xDF;
      }
      *((_BYTE *)CurrentPrcb + 248) = v12 & 0xFB;
      _InterlockedOr16((volatile signed __int16 *)(v8 + 254), 0x20u);
      *((_BYTE *)CurrentPrcb + 1747) |= 2u;
      v3 = 1;
      *((_QWORD *)CurrentPrcb + 30) = v7;
      v6 = 1;
      *((_BYTE *)CurrentPrcb + 1746) &= ~0x10u;
    }
  }
  else
  {
    if( v7 != *((_QWORD *)CurrentPrcb + 30) )
    {
      _InterlockedOr16((volatile signed __int16 *)(v8 + 254), 0x20u);
      *((_QWORD *)CurrentPrcb + 30) = v7;
      v3 = 1;
      *((_BYTE *)CurrentPrcb + 248) |= 4u;
      if( (KiSpeculationFeatures & 8) == 0 )
        *((_BYTE *)CurrentPrcb + 248) |= 0x20u;
    }
    v11 = *((_BYTE *)CurrentPrcb + 248);
    if( (v11 & 4) != 0 )
    {
      __writemsr(0x49u, 1ui64);
      *((_BYTE *)CurrentPrcb + 248) &= ~4u;
      v11 = *((_BYTE *)CurrentPrcb + 248);
    }
    if( (v11 & 0x20) != 0 )
    {
      KiFlushCurrentRsb();
      *((_BYTE *)CurrentPrcb + 248) &= ~0x20u;
    }
  }
  if( v10 == 0x400000 )
  {
    _m_prefetchw((char *)CurrentPrcb + 254);
    v16 = *((_WORD *)CurrentPrcb + 127);
    if( v4 )
    {
      do
      {
        v17 = v16;
        v16 = _InterlockedCompareExchange16((volatile signed __int16 *)CurrentPrcb + 127, v16 & 0xFEFD, v16);
      }
      while( v17 != v16 );
    }
    else
    {
      do
      {
        v18 = v16;
        v16 = _InterlockedCompareExchange16((volatile signed __int16 *)CurrentPrcb + 127, v16 & 0xFEFD, v16);
      }
      while( v18 != v16 );
    }
    LOBYTE(v15) = v16;
  }
  else if( v30 )
  {
    v15 = *((_WORD *)CurrentPrcb + 127);
    v7 = 2i64;
  }
  else
  {
    do
    {
      v14 = *((_WORD *)CurrentPrcb + 127);
      v15 = v14 & 0xFEFD | 2;
    }
    while( v14 != _InterlockedCompareExchange16((volatile signed __int16 *)CurrentPrcb + 127, v15, v14) );
    v7 = 2i64;
  }
  v19 = *(_QWORD *)(v8 + 240);
  v20 = 0;
  if( !v19 && (v15 & 0x10) != 0 )
  {
    v19 = 1i64;
    _InterlockedOr16((volatile signed __int16 *)CurrentPrcb + 127, 2u);
  }
  if( v7 == v19 || (v15 & 8) != 0 )
  {
    do
    {
      v21 = *(_WORD *)(v8 + 254);
      v22 = v21 & 0xFFEE | 1;
      if( v7 )
        v22 = v21 & 0xFFEE | 0x11;
      v23 = v22 | 2;
      if( (v15 & 1) != 0 )
        v23 = v22;
    }
    while( (v23 & 0x100) == 0
         && v23 != v21
         && v21 != _InterlockedCompareExchange16((volatile signed __int16 *)(v8 + 254), v23, v21) );
    if( (v21 & 0x100) != 0 )
    {
      v19 = 1i64;
    }
    else
    {
      v19 = *(_QWORD *)(v8 + 240);
      if( !v19 && (v15 & 0x10) != 0 )
      {
        v19 = 1i64;
        _InterlockedOr16((volatile signed __int16 *)CurrentPrcb + 127, 2u);
      }
    }
  }
  if( v19 != v7 && (v15 & 8) == 0 || v30 || v19 == 1 )
  {
    do
      v24 = *(_WORD *)(v8 + 254);
    while( (((unsigned __int8)v24 | (unsigned __int8)v15) & 1) != 0
         && v24 != _InterlockedCompareExchange16((volatile signed __int16 *)(v8 + 254), v24 & 0xFFEC | 2, v24) );
    *((_BYTE *)CurrentPrcb + 253) |= 2u;
    if( (KiSpeculationFeatures & 0x2000000) != 0 )
      *((_BYTE *)CurrentPrcb + 251) |= 2u;
  }
  else
  {
    *((_BYTE *)CurrentPrcb + 253) &= ~2u;
    if( (KiSpeculationFeatures & 0x2000000) != 0 )
      *((_BYTE *)CurrentPrcb + 251) &= ~2u;
    v20 = 1;
  }
  if( v3 )
  {
    do
      v25 = *(_WORD *)(v8 + 254);
    while( v25 != _InterlockedCompareExchange16((volatile signed __int16 *)(v8 + 254), v25 & 0xFFDD | 2, v25) );
  }
  if( !v20 )
  {
    if( v30 )
    {
      _m_prefetchw((char *)CurrentPrcb + 254);
      v26 = *((_WORD *)CurrentPrcb + 127);
      do
      {
        v27 = v26;
        v26 = _InterlockedCompareExchange16((volatile signed __int16 *)CurrentPrcb + 127, v26 | 0x100, v26);
      }
      while( v27 != v26 );
      if( (v26 & 1) != 0 && v4 )
        v2 = 1;
    }
  }
  v28 = *((_BYTE *)CurrentPrcb + 251);
  if( (KiSpeculationFeatures & 0x2000000) != 0 )
    v28 = *((_BYTE *)CurrentPrcb + 1744);
  if( v7 )
  {
    if( (v28 & 3) != 0 )
      goto LABEL_75;
    v28 = v28 & 0xFC | 1;
    *((_BYTE *)CurrentPrcb + 1744) = v28;
    if( (KiSpeculationFeatures & 0x2000000) != 0 )
      goto LABEL_75;
  }
  else
  {
    if( (v15 & 0x10) == 0 )
    {
      v28 &= 0xFCu;
      *((_BYTE *)CurrentPrcb + 1744) = v28;
      if( (KiSpeculationFeatures & 0x2000000) != 0 )
      {
        *((_BYTE *)CurrentPrcb + 251) &= ~2u;
        *((_BYTE *)CurrentPrcb + 253) &= ~2u;
      }
      else
      {
        *((_BYTE *)CurrentPrcb + 253) &= ~2u;
        *((_BYTE *)CurrentPrcb + 251) = v28;
      }
      goto LABEL_75;
    }
    v28 = v28 & 0xFC | 2;
  }
  *((_BYTE *)CurrentPrcb + 251) = v28;
LABEL_75:
  result = v2;
  if( v6 )
  {
    *((_BYTE *)CurrentPrcb + 1746) &= ~0x10u;
    *((_BYTE *)CurrentPrcb + 1745) = v28;
  }
  return result;
}

Referenced by:

KePrepareToDispatchVirtualProcessor
KiApcInterrupt
KiBoundFault
KiControlProtectionFault
KiCopyCounters
KiDpcInterrupt
KiExceptionDispatch
KiFastFailDispatch
KiInvalidOpcodeFault
KiIpiInterrupt
KiPageFault
KiRestoreSetContextState
KiSpuriousDispatchNoEOI
KiSwInterrupt
KiSystemCall64
KiUmsFastReturnToUser
KiUpdateSpeculationControl
KiVirtualizationException
KxIsrLinkage
KxMcheckAlternateReturn
KxStartUserThread
NtCallEnclave
NtContinueEx
NtRaiseException