ViCtxCaptureInitialIsrState

char *__fastcall ViCtxCaptureInitialIsrState(__int64 a1){
  int v1; 
  char *v2; 
  UINT64 v3; 

  _InterlockedAdd(&ViCtxInterrupts, 1u);
  v1 = 0;
  while( 1 )
  {
    v2 = (char *)&ViCtxIsrStateBlocks + 80 * (((unsigned __int8)_InterlockedExchangeAdd(&ViCtxHintIndex, 1u) + 1) & 0xF);
    if( !_InterlockedCompareExchange((volatile signed __int32 *)v2, 1, 0) )
      break;
    if( (unsigned int)++v1 >= 0x10 )
    {
      v2 = 0i64;
      break;
    }
  }
  if( v2 )
  {
    v3 = ViCtxXStateEnabledMask;
    v2[8] = KeGetCurrentIrql();
    if( ((v3 & 0xFFFFFFFFFFFFFFFCui64) != 0 || !*(_BYTE *)(a1 + 94)) && (*((_DWORD *)v2 + 1) & 1) != 0 )
    {
      RtlXSave(*((_XSAVE_AREA **)v2 + 4), v3);
      *((_DWORD *)v2 + 1) |= 2u;
    }
    _InterlockedAdd(&ViCtxInterruptsChecked, 1u);
  }
  return v2;
}

Referenced by:

ViCtxIsr
ViCtxIsrMessageBased