PopSetPowerSettingValue

__int64 __fastcall PopSetPowerSettingValue(LPCGUID SettingGuid, int a2, int a3, unsigned int a4, void *Src){
  UINT64 v5; 
  GUID *v7; 
  char v8; 
  INT64 v9; 
  UINT8 *v10; 
  LIST_ENTRY *v11; 
  _LIST_ENTRY *v12; 
  unsigned int v13; 
  char v14; 
  __int64 v16; 
  INT64 *v17; 
  char v18; 
  __int64 i; 
  bool v20; 
  VOID *v21; 
  signed __int32 v22; 
  LIST_ENTRY *j; 
  LIST_ENTRY *v24; 
  const WCHAR *v25; 
  UINT64 v26; 
  INT64 v27; 
  _LIST_ENTRY *v28; 
  __int64 *v29; 
  _LIST_ENTRY *v30; 
  __int64 *v31; 
  __int64 *v32; 
  __int64 v33; 
  __int64 **v34; 
  __int64 **v35; 
  __int64 *Blink; 
  _LIST_ENTRY *v37; 
  UINT8 IsSessionSpecific; 
  char v39; 
  char v40; 
  UINT8 *PoolWithTag; 
  LIST_ENTRY *PowerSettingConfiguration; 
  v5 = a4;
  v39 = 0;
  v7 = (GUID *)SettingGuid;
  v8 = 0;
  v9 = 0i64;
  v40 = 0;
  PoolWithTag = (UINT8 *)ExAllocatePoolWithTag(PagedPool, a4, 0x74655350ui64);
  v10 = PoolWithTag;
  if( !PoolWithTag )
    return 3221225626i64;
  PopIncrementPowerSettingPendingUpdates(0);
  memmove(PoolWithTag, (UINT8 *)Src, (unsigned int)v5);
  PopValidatePowerSettingData(v7, (unsigned int)v5, PoolWithTag);
  IsSessionSpecific = PopStateIsSessionSpecific(v7);
  ExAcquireFastMutex(&PopSettingLock);
  PowerSettingConfiguration = PopFindPowerSettingConfiguration(v7, (unsigned int)a2);
  v11 = PowerSettingConfiguration;
  if( !PowerSettingConfiguration )
  {
    v24 = (LIST_ENTRY *)ExAllocatePoolWithTag(PagedPool, 0x58ui64, 0x74655350ui64);
    PowerSettingConfiguration = v24;
    v11 = v24;
    if( !v24 )
    {
      v13 = -1073741670;
      v14 = 0;
      goto LABEL_6;
    }
    memset((INT64)v24, 0i64);
    v11[2] = *(LIST_ENTRY *)v7;
    LOBYTE(v28) = PopGetListHead((INT64)v7, v25, v26, v27);
    v29 = (__int64 *)&v11[1];
    v30 = v28;
    v11[1].Blink = v11 + 1;
    v11[1].Flink = v11 + 1;
    if( !IsSessionSpecific )
    {
      v31 = (__int64 *)PopRegisteredPowerSettingCallbacks;
      while( v31 != &PopRegisteredPowerSettingCallbacks )
      {
        v32 = v31;
        v31 = (__int64 *)*v31;
        v33 = *(__int64 *)((char *)v32 + 36) - *(_QWORD *)&v7->Data1;
        if( !v33 )
          v33 = *(__int64 *)((char *)v32 + 44) - *(_QWORD *)v7->Data4;
        if( !v33 )
        {
          v34 = (__int64 **)v31[1];
          if( *v34 != v31 )
            goto LABEL_61;
          v35 = (__int64 **)v34[1];
          if( *v35 != (__int64 *)v34 )
            goto LABEL_61;
          v31[1] = (__int64)v35;
          *v35 = v31;
          Blink = (__int64 *)v11[1].Blink;
          if( (__int64 *)*Blink != v29 )
            goto LABEL_61;
          *v34 = v29;
          v34[1] = Blink;
          *Blink = (__int64)v34;
          v11[1].Blink = (_LIST_ENTRY *)v34;
        }
      }
      a2 = -1;
    }
    LODWORD(v11[3].Flink) = a2;
    v37 = v30->Blink;
    if( v37->Flink != v30 )
LABEL_61:
      __fastfail(3u);
    v11->Blink = v37;
    v11->Flink = v30;
    v37->Flink = v11;
    v30->Blink = v11;
    v39 = 1;
    if( PopPopPowerSettingSetChangeNotification )
      v40 = 1;
  }
  v12 = (_LIST_ENTRY *)*((_QWORD *)&v11[4].Flink + a3);
  if( PopArePowerSettingsEqual((INT64)v12, PoolWithTag, (unsigned int)v5) )
  {
    v8 = 0;
    v13 = 0;
  }
  else
  {
    v16 = a3;
    v17 = (INT64 *)&v11[4];
    v18 = 0;
    for( i = 0i64; i < 3; ++i )
    {
      if( i != v16 )
      {
        if( !v9 )
        {
          v20 = !PopArePowerSettingsEqual(*v17, PoolWithTag, (unsigned int)v5);
          v16 = a3;
          if( !v20 )
          {
            v9 = *v17;
            ++*(_DWORD *)*v17;
          }
        }
        if( (_LIST_ENTRY *)*v17 == v12 )
          v18 = 1;
      }
      ++v17;
    }
    v13 = 0;
    if( v9 )
    {
      v10 = PoolWithTag;
      v14 = 1;
    }
    else
    {
      v21 = ExAllocatePoolWithTag(PagedPool, (unsigned int)(v5 + 12), 0x74655350ui64);
      v9 = (INT64)v21;
      if( !v21 )
      {
        v8 = 0;
        v13 = -1073741670;
        v10 = PoolWithTag;
        v7 = (GUID *)SettingGuid;
        v14 = 0;
        goto LABEL_6;
      }
      memset((INT64)v21, 0i64);
      v14 = 1;
      *(_DWORD *)(v9 + 4) = v5;
      *(_DWORD *)v9 = 1;
      do
        v22 = _InterlockedIncrement(&PopPowerSettingChangeStamp);
      while( !v22 );
      v10 = PoolWithTag;
      *(_DWORD *)(v9 + 8) = v22;
      memmove((UINT8 *)(v9 + 12), PoolWithTag, v5);
    }
    if( v12 )
    {
      if( !v18 )
      {
        for( j = PowerSettingConfiguration[1].Flink; j != &PowerSettingConfiguration[1]; j = j->Flink )
        {
          if( j[4].Blink == v12 )
            j[4].Blink = 0i64;
        }
      }
      v20 = LODWORD(v12->Flink)-- == 1;
      if( v20 )
        ExFreePoolWithTag(v12, 0x74655350u);
    }
    v8 = 0;
    *((_QWORD *)&PowerSettingConfiguration[4].Flink + a3) = v9;
    if( dword_140C23D0C == a3 && !IsSessionSpecific )
      v8 = 1;
    if( LODWORD(PowerSettingConfiguration[3].Blink) || HIDWORD(PowerSettingConfiguration[3].Blink) )
    {
      v7 = (GUID *)SettingGuid;
      HIDWORD(PowerSettingConfiguration[3].Flink) |= 1u;
      goto LABEL_6;
    }
    v7 = (GUID *)SettingGuid;
  }
  v14 = 0;
LABEL_6:
  KeReleaseGuardedMutex(&PopSettingLock);
  if( v39 )
    PoRegisterPowerSettingCallback(0i64, v7, (PPOWER_SETTING_CALLBACK)PopTracePowerSettingChange, 0i64, 0i64);
  ExFreePoolWithTag(v10, 0x74655350u);
  if( (unsigned int)PopOsInitPhase >= 3 )
  {
    if( v40 )
      ZwUpdateWnfStateData();
    if( v8 )
    {
      PopIncrementPowerSettingPendingUpdates(1u);
      PopSetNotificationWork(0x20ui64);
    }
    if( v14 )
      PopSetNotificationWork(0x80ui64);
  }
  PopDecrementPowerSettingPendingUpdates(0i64);
  return v13;
}

Referenced by:

PopInitilizeAcDcSettings
PopScanIdleList
PopSetNewPolicyValue
PopSetPowerSettingValueAcDc
PopSetSessionDisplayStatus
PopSetSessionUserStatus