PiControlGetDevicePowerData

__int64 __fastcall PiControlGetDevicePowerData(__int64 a1, __int64 a2, unsigned int a3, _OWORD *a4, _DWORD *a5){
  UINT64 v5; 
  unsigned int v8; 
  _DEVICE_POWER_STATE DoDevicePowerState; 
  int v11; 
  __int64 v12; 
  __int64 v13; 
  _DEVICE_POWER_STATE DeviceWake; 
  _SYSTEM_POWER_STATE SystemWake; 
  __int32 v16; 
  __int32 v17; 
  __int32 v18; 
  __int64 v19; 
  __int128 v20; 
  __int128 v21; 
  __int128 Src; 
  __m256i v23; 
  __int64 v24; 
  DEVICE_CAPABILITIES result; 
  v5 = a3;
  memset((INT64)&result, 0i64);
  v8 = 0;
  DWORD2(Src) = 0;
  *a5 = 0;
  LODWORD(Src) = 56;
  if( (unsigned int)v5 < 4 )
  {
    *a5 = 56;
    return 2147483653i64;
  }
  if( PpIrpQueryCapabilities(*(DEVICE_OBJECT **)(a1 + 32), &result) < 0 )
    return 3221225486i64;
  if( (unsigned int)PipIsDevNodeDNStarted((_DEVICE_NODE *)a1) )
  {
    DoDevicePowerState = PopLockGetDoDevicePowerState(*(DEVOBJ_EXTENSION **)(*(_QWORD *)(a1 + 32) + 312i64));
    if( DoDevicePowerState == PowerDeviceUnspecified )
      DoDevicePowerState = PowerDeviceD0;
    DWORD1(Src) = DoDevicePowerState;
  }
  else
  {
    DWORD1(Src) = 4;
  }
  v11 = 9;
  if( (*((_BYTE *)&result + 4) & 1) != 0 )
    v11 = 11;
  v12 = 2i64;
  DWORD2(Src) = v11;
  if( (*((_BYTE *)&result + 4) & 2) != 0 )
  {
    v11 |= 4u;
    DWORD2(Src) = v11;
  }
  if( (*((_WORD *)&result + 2) & 0x400) != 0 )
  {
    v11 |= 0x10u;
    DWORD2(Src) = v11;
  }
  if( (*((_WORD *)&result + 2) & 0x800) != 0 )
  {
    v11 |= 0x20u;
    DWORD2(Src) = v11;
  }
  if( (*((_WORD *)&result + 2) & 0x1000) != 0 )
  {
    v11 |= 0x40u;
    DWORD2(Src) = v11;
  }
  if( (*((_WORD *)&result + 2) & 0x2000) != 0 )
  {
    v11 |= 0x80u;
    DWORD2(Src) = v11;
  }
  if( (*((_DWORD *)&result + 1) & 0x10000) != 0 )
  {
    v11 |= 0x100u;
    DWORD2(Src) = v11;
  }
  v13 = 2i64;
  DeviceWake = result.DeviceWake;
  SystemWake = result.SystemWake;
  LODWORD(v24) = result.DeviceState[6];
  HIDWORD(Src) = result.D1Latency;
  v23.m256i_i64[0] = *(_QWORD *)&result.D2Latency;
  *(_OWORD *)&v23.m256i_u64[1] = *(_OWORD *)result.DeviceState;
  v23.m256i_i64[3] = *(_QWORD *)&result.DeviceState[4];
  do
  {
    v16 = DeviceWake - 1;
    if( v16 )
    {
      v17 = v16 - 1;
      if( v17 )
      {
        v18 = v17 - 1;
        if( v18 )
        {
          if( v18 != 1 )
            goto LABEL_34;
          v11 |= 0x80u;
        }
        else
        {
          v11 |= 0x44u;
        }
      }
      else
      {
        v11 |= 0x22u;
      }
    }
    else
    {
      v11 |= 0x10u;
    }
    DWORD2(Src) = v11;
LABEL_34:
    if( result.SystemWake )
      DeviceWake = result.DeviceState[result.SystemWake];
    else
      DeviceWake = PowerDeviceUnspecified;
    --v13;
  }
  while( v13 );
  if( (v11 & 0x80) != 0 )
  {
    v19 = 4i64;
    goto LABEL_42;
  }
  if( (v11 & 0x40) != 0 )
  {
    v19 = 3i64;
LABEL_42:
    v12 = v19;
  }
  else if( (v11 & 0x20) != 0 )
  {
    LODWORD(v19) = 2;
  }
  else if( (v11 & 0x10) != 0 )
  {
    LODWORD(v19) = 1;
    v12 = 1i64;
  }
  else
  {
    LODWORD(v19) = 0;
    v12 = 0i64;
  }
  if( result.SystemWake == PowerSystemUnspecified && (_DWORD)v19 )
  {
    for( SystemWake = PowerSystemSleeping3; SystemWake >= PowerSystemWorking; --SystemWake )
    {
      if( result.DeviceState[2] && (int)result.DeviceState[2] <= v12 )
        break;
    }
  }
  HIDWORD(v24) = SystemWake;
  if( (unsigned int)v5 >= 0x38 )
  {
    if( a4 )
    {
      v20 = *(_OWORD *)v23.m256i_i8;
      *a4 = Src;
      v21 = *(_OWORD *)&v23.m256i_u64[2];
      a4[1] = v20;
      *(_QWORD *)&v20 = v24;
      a4[2] = v21;
      *((_QWORD *)a4 + 6) = v20;
    }
  }
  else
  {
    if( a4 )
      memmove((UINT8 *)a4, (UINT8 *)&Src, v5);
    v8 = -2147483643;
  }
  *a5 = 56;
  return v8;
}

Referenced by:

PiControlGetPropertyData