RtlRunOnceComplete

INT64 __fastcall RtlRunOnceComplete(_RTL_RUN_ONCE *RunOnce, UINT64 Flags, VOID *Context){
  unsigned int v4; 
  signed __int64 Value; 
  unsigned __int64 v7; 
  __int64 v8; 
  __int64 v9; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  __int64 v12; 
  unsigned __int64 v13; 
  if( (((_DWORD)Flags - 1) & (unsigned int)Flags) != 0 || (Flags & 0xFFFFFFF9) != 0 )
    return 3221225712i64;
  v4 = ~(unsigned __int8)((unsigned int)Flags >> 1) & 3;
  if( Context && (((unsigned __int8)Context & 3) != 0 || (v4 & 2) == 0) )
    return 3221225713i64;
  _m_prefetchw(RunOnce);
  Value = RunOnce->Value;
  v7 = RunOnce->Value & 3;
  v8 = (unsigned __int64)Context & 0xFFFFFFFFFFFFFFFCui64 | (v4 >= 2 ? 2 : 0);
  if( v7 == 1 )
  {
    if( (v4 & 1) != 0 )
    {
      v9 = _InterlockedExchange64((volatile __int64 *)RunOnce, v8);
      if( (v9 & 3) == 1 )
      {
        v10 = v9 & 0xFFFFFFFFFFFFFFFCui64;
        if( v10 )
        {
          do
          {
            v11 = *(_QWORD *)v10;
            v12 = *(_QWORD *)(v10 + 24);
            _interlockedbittestandset((volatile signed __int32 *)(v10 + 36), 2u);
            KeAlertThreadByThreadId(v12);
            v10 = v11;
          }
          while( v11 );
        }
        return 0i64;
      }
      return 3221225562i64;
    }
    return 3221225712i64;
  }
  if( v7 != 3 )
    return 3221225473i64;
  if( (v4 & 1) != 0 )
    return 3221225712i64;
  v13 = RunOnce->Value;
  if( v13 == _InterlockedCompareExchange64((volatile signed __int64 *)RunOnce, v8, Value) )
    return 0i64;
  return 3221225525i64;
}

Referenced by:

RtlRunOnceExecuteOnce