CmCreateOrdinalInstanceKey

__int64 __fastcall CmCreateOrdinalInstanceKey(__int64 a1, __int64 a2, wchar_t *a3, __int64 a4, __int64 a5, HANDLE *a6){
  unsigned int v9; 
  unsigned int v10; 
  unsigned int v11; 
  unsigned int i; 
  wchar_t v13; 
  int v14; 
  wchar_t *v15; 
  int v16; 
  bool v18; 
  __int64 v19; 
  int v20; 
  HANDLE Handle; 
  ULONG v22; 
  v22 = 0;
  Handle = 0i64;
  v9 = 0;
  v10 = wcstoul(L"999A", 0i64, 36i64);
  v11 = wcstoul(L"ZZZZ", 0i64, 36i64);
  if( v10 - 1 > 0xFFFFFFFD || v11 - 1 > 0xFFFFFFFD )
    return(unsigned int)-1073741595;
  for( i = 0; ; i = v10 )
  {
LABEL_4:
    if( i <= 0x270F )
    {
      if( (int)swprintf_s(a3, 5ui64, (WCHAR *)L"%04u") >= 0 )
        goto LABEL_6;
      return(unsigned int)-1073741595;
    }
    if( i >= v10 )
      break;
  }
  if( i > v11 )
    return(unsigned int)-2147483622;
  if( ultow_s(i, a3, 5ui64, 36) )
    return(unsigned int)-1073741595;
LABEL_6:
  v13 = *a3;
  v14 = 1;
  v15 = a3;
  while( 2 )
  {
    if( v13 )
    {
      if( v13 > 0x61u )
      {
        if( v13 == 101 || v13 == 105 || v13 == 111 )
        {
LABEL_39:
          v19 = v15 - a3;
          v20 = 3 - v19;
          if( (_DWORD)v19 != 3 )
          {
            do
            {
              v14 *= 36;
              --v20;
            }
            while( v20 );
          }
          goto LABEL_20;
        }
        if( v13 <= 0x74u )
          goto LABEL_15;
        if( v13 <= 0x76u )
          goto LABEL_39;
        v18 = v13 == 121;
      }
      else
      {
        if( v13 == 97 || v13 == 65 || v13 == 69 || v13 == 73 || v13 == 79 )
          goto LABEL_39;
        if( v13 <= 0x54u )
          goto LABEL_15;
        if( v13 <= 0x56u )
          goto LABEL_39;
        v18 = v13 == 89;
      }
      if( v18 )
        goto LABEL_39;
LABEL_15:
      v13 = *++v15;
      continue;
    }
    break;
  }
  v16 = PnpCtxRegCreateKey(a1, a2, a3, 0, 1u, 0i64, &Handle, &v22);
  if( v16 == -1073741444 )
    return(unsigned int)-1073741595;
  if( v16 < 0 )
  {
    return(unsigned int)v16;
  }
  else
  {
    if( v22 != 1 )
    {
      ZwClose(Handle);
      Handle = 0i64;
LABEL_20:
      i += v14;
      goto LABEL_4;
    }
    *a6 = Handle;
  }
  return v9;
}

Referenced by:

CmGetDeviceSoftwareKey