CmDeleteDeviceInterfaceWorker

__int64 __fastcall CmDeleteDeviceInterfaceWorker(__int64 a1, const WCHAR *a2, __int16 a3, __int64 a4){
  int v4; 
  int *v7; 
  unsigned int v8; 
  int v9; 
  int v10; 
  __int64 v11; 
  void *PoolWithTag; 
  unsigned int v13; 
  int DeviceInterfaceMappedPropertyKeys; 
  __int64 v15; 
  __int64 v16; 
  int v17; 
  __int64 v18; 
  unsigned int v20; 
  unsigned int v21; 
  int v22[4]; 
  v4 = 0;
  if( a3 )
  {
    return(unsigned int)-1073741811;
  }
  else
  {
    v22[0] = 768;
    v7 = v22;
    v22[1] = 512;
    v8 = 0;
    v22[2] = 256;
    while( 1 )
    {
      v9 = *v7;
      v10 = CmDeleteDeviceInterfaceRegKey(a1, a2, *v7 | 0x30u, a4, 1);
      if( v10 )
      {
        if( v10 != -1073741637 && v10 != -1073741772 && v10 != -1073741811 )
          break;
      }
      v10 = CmDeleteDeviceInterfaceRegKey(a1, a2, v9 | 0x31u, v11, 0);
      if( v10 )
      {
        if( v10 != -1073741637 && v10 != -1073741772 && v10 != -1073741811 && v10 != -1073741535 )
          break;
      }
      ++v8;
      ++v7;
      if( v8 >= 3 )
        goto LABEL_8;
    }
    v4 = v10;
    if( v10 < 0 )
      return(unsigned int)v4;
LABEL_8:
    PoolWithTag = 0i64;
    v13 = 0;
    v21 = 0;
    do
    {
      DeviceInterfaceMappedPropertyKeys = CmGetDeviceInterfaceMappedPropertyKeys(
                                            a1,
                                            a2,
                                            0i64,
                                            1,
                                            (__int64)PoolWithTag,
                                            v13,
                                            &v21);
      v13 = v21;
      if( DeviceInterfaceMappedPropertyKeys != -1073741789 )
        goto LABEL_10;
      v20 = 20 * v21;
      if( 20 * (unsigned __int64)v21 > 0xFFFFFFFF )
      {
        DeviceInterfaceMappedPropertyKeys = -1073741811;
        goto LABEL_32;
      }
      if( PoolWithTag )
        ExFreePoolWithTag(PoolWithTag, 0);
      PoolWithTag = ExAllocatePoolWithTag(PagedPool, v20, 0x52504E50ui64);
    }
    while( PoolWithTag );
    DeviceInterfaceMappedPropertyKeys = -1073741801;
LABEL_10:
    if( DeviceInterfaceMappedPropertyKeys && DeviceInterfaceMappedPropertyKeys != -1073741275 )
    {
LABEL_32:
      v4 = DeviceInterfaceMappedPropertyKeys;
      goto LABEL_19;
    }
    v16 = 0i64;
    if( v13 )
    {
      while( 1 )
      {
        v17 = CmSetDeviceInterfaceMappedProperty(a1, a2, 0i64, 0i64, (__int64)PoolWithTag + 20 * v16, 0, 0i64, 0);
        if( v17 )
        {
          if( v17 != -1073741790 && v17 != -1073741275 && v17 != -1073741802 && v17 != -1073741637 )
            break;
        }
        v16 = (unsigned int)(v16 + 1);
        if( (unsigned int)v16 >= v13 )
          goto LABEL_15;
      }
      v4 = v17;
    }
LABEL_15:
    if( v4 >= 0 )
    {
      DeviceInterfaceMappedPropertyKeys = CmDeleteDeviceInterfaceRegKey(a1, a2, 48, v15, 1);
      if( !DeviceInterfaceMappedPropertyKeys
        || DeviceInterfaceMappedPropertyKeys == -1073741772
        || DeviceInterfaceMappedPropertyKeys == -1073741811 )
      {
        DeviceInterfaceMappedPropertyKeys = CmDeleteDeviceInterfaceRegKey(a1, a2, 49, v18, 0);
        if( !DeviceInterfaceMappedPropertyKeys
          || DeviceInterfaceMappedPropertyKeys == -1073741772
          || DeviceInterfaceMappedPropertyKeys == -1073741811
          || DeviceInterfaceMappedPropertyKeys == -1073741535 )
        {
          CmRaiseDeleteEvent(a1, (__int64)a2, 3u);
          goto LABEL_19;
        }
      }
      goto LABEL_32;
    }
LABEL_19:
    if( PoolWithTag )
      ExFreePoolWithTag(PoolWithTag, 0);
  }
  return(unsigned int)v4;
}

Referenced by:

CmDeleteDeviceInterface