KiStartProfileTarget

VOID __stdcall KiStartProfileTarget(UINT64 Argument){
  __int64 v1; 
  unsigned __int8 CurrentIrql; 
  int v4; 
  __int64 v5; 
  _LIST_ENTRY *v6; 
  _LIST_ENTRY **v7; 
  _LIST_ENTRY *v8; 
  _LIST_ENTRY *Blink; 
  __int64 v10; 
  __int64 v11; 
  _KAFFINITY_EX *v12; 
  struct _KPRCB *CurrentPrcb; 
  int v14[8]; 
  __int128 v15; 
  __int64 v16; 
  unsigned int v17; 
  v1 = *(_QWORD *)Argument;
  v17 = 0;
  v16 = 0i64;
  v15 = 0i64;
  CurrentIrql = KeGetCurrentIrql();
  __writecr8((unsigned __int8)KiProfileIrql);
  v4 = (unsigned __int8)v16 + 1;
  if( !_InterlockedDecrement((volatile signed __int32 *)(Argument + 8)) )
  {
    if( *(_BYTE *)(v1 + 242) )
    {
      *(_BYTE *)(Argument + 192) = 0;
      goto LABEL_4;
    }
    v5 = *(_QWORD *)(v1 + 24);
    v6 = (_LIST_ENTRY *)(v1 + 8);
    *(_BYTE *)(v1 + 242) = v4;
    if( v5 )
    {
      v7 = *(_LIST_ENTRY ***)(v5 + 32);
      v8 = (_LIST_ENTRY *)(v5 + 24);
      if( *v7 != v8 )
        goto LABEL_21;
      v6->Flink = v8;
      *(_QWORD *)(v1 + 16) = v7;
      *v7 = v6;
      v8->Blink = v6;
    }
    else
    {
      Blink = KiProfileListHead.Blink;
      if( KiProfileListHead.Blink->Flink != &KiProfileListHead )
        goto LABEL_21;
      v6->Flink = &KiProfileListHead;
      *(_QWORD *)(v1 + 16) = Blink;
      Blink->Flink = v6;
      KiProfileListHead.Blink = (_LIST_ENTRY *)(v1 + 8);
    }
    v10 = KiProfileSourceListHead;
    if( (__int64 *)KiProfileSourceListHead != &KiProfileSourceListHead )
    {
      while( *(_DWORD *)(v10 + 16) != *(__int16 *)(v1 + 240) )
      {
        v10 = *(_QWORD *)v10;
        if( (__int64 *)v10 == &KiProfileSourceListHead )
          goto LABEL_15;
      }
      goto LABEL_17;
    }
LABEL_15:
    v10 = *(_QWORD *)(Argument + 184);
    *(_QWORD *)(Argument + 184) = 0i64;
    *(_DWORD *)(v10 + 16) = *(__int16 *)(v1 + 240);
    *(_DWORD *)(v10 + 28) = 0;
    *(_DWORD *)(v10 + 24) = 1310721;
    memset(v10 + 32, 0i64);
    v11 = KiProfileSourceListHead;
    if( *(__int64 **)(KiProfileSourceListHead + 8) == &KiProfileSourceListHead )
    {
      *(_QWORD *)v10 = KiProfileSourceListHead;
      *(_QWORD *)(v10 + 8) = &KiProfileSourceListHead;
      *(_QWORD *)(v11 + 8) = v10;
      KiProfileSourceListHead = v10;
LABEL_17:
      *((_QWORD *)&v15 + 1) = *(_QWORD *)(v1 + 80);
      *(_QWORD *)&v15 = v1 + 72;
      while( !(unsigned int)KeEnumerateNextProcessor(&v17, (unsigned __int16 **)&v15) )
        *(_DWORD *)(v10 + 4i64 * v17 + 192) += v4;
      v12 = (_KAFFINITY_EX *)(v10 + 24);
      KeSubtractAffinityEx((_KAFFINITY_EX *)(v1 + 72), v12, (_KAFFINITY_EX *)(Argument + 16));
      _InterlockedOr(v14, 0);
      KeOrAffinityEx(v12, (_KAFFINITY_EX *)(v1 + 72), v12);
      *(_BYTE *)(Argument + 192) = v4;
      goto LABEL_4;
    }
LABEL_21:
    __fastfail(3u);
  }
LABEL_4:
  _InterlockedAdd((volatile signed __int32 *)(Argument + 12), 0xFFFFFFFF);
  while( *(int *)(Argument + 12) > 0 )
    _mm_pause();
  CurrentPrcb = KeGetCurrentPrcb();
  if( (*(_QWORD *)(Argument + 8i64 * *((unsigned __int8 *)CurrentPrcb + 208) + 24) & *((_QWORD *)CurrentPrcb + 25)) != 0i64 )
    HalStartProfileInterrupt((KPROFILE_SOURCE)*(__int16 *)(v1 + 240));
  __writecr8(CurrentIrql);
}

Referenced by:

KeStartProfile