RegRtlDeletePathInternal

__int64 __fastcall RegRtlDeletePathInternal(char *a1, const wchar_t *a2, char a3, __int64 a4, int a5){
  int v9; 
  UINT64 v10; 
  WCHAR *PoolWithTag; 
  WCHAR *v12; 
  char i; 
  int v14; 
  WCHAR *v15; 
  UINT64 dwFlags; 
  int v18; 
  HANDLE Handle; 
  __int64 pcchLength[2]; 
  pcchLength[0] = 0i64;
  Handle = 0i64;
  a5 = 0;
  v18 = 0;
  v9 = RtlUnalignedStringCchLengthW(a2, 0x7FFFui64, (SIZE_T *)pcchLength);
  if( v9 < 0 )
    return(unsigned int)v9;
  v10 = pcchLength[0] + 1;
  PoolWithTag = (WCHAR *)ExAllocatePoolWithTag(PagedPool, 2 * (pcchLength[0] + 1), 0x4C474552ui64);
  v12 = PoolWithTag;
  if( !PoolWithTag )
    return(unsigned int)-1073741801;
  LODWORD(dwFlags) = 256;
  v9 = RtlStringCchCopyExW(PoolWithTag, v10, (WCHAR *)a2, 0i64, 0i64, dwFlags);
  if( v9 )
    goto LABEL_26;
  for( i = 1; ; i = 0 )
  {
    if( i && a3 )
    {
      v14 = RegRtlDeleteTreeInternal(a1, v12, a4, 0);
      goto LABEL_17;
    }
    v9 = RegRtlOpenKeyTransacted(a1, v12, 0, 1u, &Handle, a4);
    if( !v9 )
    {
      v9 = RegRtlQueryInfoKey(Handle, &a5, 0i64, &v18, 0i64, 0i64);
      ZwClose(Handle);
      if( v9 != -1073741444 && v9 )
        goto LABEL_26;
      if( a5 || v18 )
      {
        v9 = -1073741535;
        goto LABEL_26;
      }
      goto LABEL_16;
    }
    if( v9 != -1073741772 )
      break;
LABEL_16:
    v14 = RegRtlDeleteKeyTransacted(a1, v12, 0i64);
LABEL_17:
    v9 = v14;
    if( v14 && v14 != -1073741772 )
      goto LABEL_26;
    v15 = wcsrchr(v12, 0x5Cu);
    if( !v15 )
      goto LABEL_26;
    for( *v15 = 0; v15 != v12; *v15 = 0 )
    {
      if( *--v15 != 92 )
        break;
    }
  }
  if( v9 == -1073741444 )
    v9 = 0;
LABEL_26:
  ExFreePoolWithTag(v12, 0);
  return(unsigned int)v9;
}

Referenced by:

PiDevCfgClearDeviceMigrationNode