CmCreateOrdinalInstanceKey

NTSTATUS __stdcall CmCreateOrdinalInstanceKey(
        HPNPCTX *hPnpCtx,
        VOID *BaseKeyHandle,
        WCHAR *InstanceKeyPath,
        UINT64 InstanceKeyLength,
        UINT64 DesiredAccess,
        VOID **InstanceKeyHandle){
  NTSTATUS v9; 
  unsigned int v10; 
  unsigned int v11; 
  unsigned int i; 
  WCHAR v13; 
  int v14; 
  WCHAR *v15; 
  int v16; 
  bool v18; 
  __int64 v19; 
  int v20; 
  UINT64 v21; 
  VOID *Handle; 
  UINT64 pRegDisposition; 

  LODWORD(pRegDisposition) = 0;
  Handle = 0i64;
  v9 = 0;
  v10 = wcstoul((WCHAR *)L"999A", 0i64, 36i64);
  v11 = wcstoul((WCHAR *)L"ZZZZ", 0i64, 36i64);
  if( v10 - 1 > 0xFFFFFFFD || v11 - 1 > 0xFFFFFFFD )
    return -1073741595;
  for( i = 0; ; i = v10 )
  {
LABEL_4:
    if( i <= 0x270F )
    {
      if( (int)swprintf_s(InstanceKeyPath, 5ui64, (WCHAR *)L"%04u", i) >= 0 )
        goto LABEL_6;
      return -1073741595;
    }
    if( i >= v10 )
      break;
  }
  if( i > v11 )
    return -2147483622;
  if( ultow_s(i, InstanceKeyPath, 5u, 36) )
    return -1073741595;
LABEL_6:
  v13 = *InstanceKeyPath;
  v14 = 1;
  v15 = InstanceKeyPath;
  while( 2 )
  {
    if( v13 )
    {
      if( v13 > 0x61u )
      {
        if( v13 == 101 || v13 == 105 || v13 == 111 )
        {
LABEL_39:
          v19 = v15 - InstanceKeyPath;
          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;
  }
  LODWORD(v21) = 1;
  v16 = PnpCtxRegCreateKey(hPnpCtx, BaseKeyHandle, InstanceKeyPath, 0i64, v21, 0i64, &Handle, &pRegDisposition);
  if( v16 == -1073741444 )
    return -1073741595;
  if( v16 < 0 )
    return v16;
  if( (_DWORD)pRegDisposition != 1 )
  {
    ZwClose((_HANDLE)Handle);
    Handle = 0i64;
LABEL_20:
    i += v14;
    goto LABEL_4;
  }
  *InstanceKeyHandle = Handle;
  return v9;
}

Referenced by:

CmGetDeviceSoftwareKey