PnpCtxGetCachedNodeBaseKey

__int64 __fastcall PnpCtxGetCachedNodeBaseKey(__int64 a1, __int64 *a2, UINT64 a3, __int64 *a4){
  int Tree; 
  void *EnumSecurityDescriptor; 
  int v6; 
  __int64 v8; 
  int v9; 
  int v10; 
  __int64 v11; 
  int v13; 
  int CachedContextBaseKey; 
  __int64 v15; 
  int v16; 
  int v17; 
  int v18; 
  const wchar_t *p_Xmm7; 
  int v20; 
  int v21; 
  int v22; 
  int v23; 
  int v24; 
  int v25; 
  __int64 v26; 
  int v27; 
  int v28; 
  int v29; 
  int v30; 
  int v31; 
  __int64 v32; 
  __int64 v33; 
  void *v34; 
  __int64 *v35; 
  v35 = a4;
  Tree = 0;
  EnumSecurityDescriptor = 0i64;
  v33 = 0i64;
  v6 = a3;
  v34 = 0i64;
  v8 = a1;
  v9 = 4;
  v10 = 1;
  if( (int)a3 > 8 )
  {
    switch( (_DWORD)a3 )
    {
      case 9:
        v33 = a2[12];
        goto LABEL_18;
      case 0xA:
        v11 = a2[13];
        break;
      case 0xB:
        v11 = a2[14];
        break;
      case 0xC:
        v11 = a2[15];
        break;
      case 0xD:
        v11 = a2[16];
        break;
      case 0xE:
        v11 = a2[17];
        break;
      case 0xF:
        v11 = a2[18];
        break;
      default:
        return(unsigned int)-1073741811;
    }
LABEL_9:
    v33 = v11;
    goto LABEL_10;
  }
  switch( (_DWORD)a3 )
  {
    case 8:
      v11 = a2[11];
      goto LABEL_9;
    case 1:
      v13 = 1;
      break;
    case 2:
      v13 = 2;
      break;
    case 3:
      v13 = 3;
      break;
    case 4:
      v13 = 4;
      break;
    default:
      switch( (_DWORD)a3 )
      {
        case 5:
          v11 = a2[8];
          break;
        case 6:
          v11 = a2[9];
          break;
        case 7:
          v11 = a2[10];
          break;
        default:
          return(unsigned int)-1073741811;
      }
      goto LABEL_9;
  }
  CachedContextBaseKey = SysCtxGetCachedContextBaseKey((_QWORD *)a2[7], v13, &v33);
  a4 = v35;
  Tree = CachedContextBaseKey;
LABEL_18:
  if( Tree < 0 )
    return(unsigned int)Tree;
LABEL_10:
  if( v33 )
  {
    *a4 = v33;
    return(unsigned int)Tree;
  }
  if( v6 < 5 || v6 > 15 )
    Tree = -1073741811;
  if( Tree >= 0 )
  {
    if( v6 > 10 )
    {
      if( v6 == 11 )
      {
        p_Xmm7 = L"Control\\DevicePanels";
        goto LABEL_48;
      }
      v20 = v6 - 11 - v10;
      if( !v20 )
      {
        p_Xmm7 = L"Control\\CriticalDeviceDatabase";
        goto LABEL_48;
      }
      v21 = v20 - v10;
      if( !v21 )
      {
        p_Xmm7 = L"Control\\CoDeviceInstallers";
        goto LABEL_48;
      }
      v30 = v21 - v10;
      if( !v30 )
      {
        p_Xmm7 = L"Hardware Profiles";
        goto LABEL_48;
      }
      if( v30 == v10 )
      {
        v9 = v10;
        p_Xmm7 = L"HardwareConfig";
        goto LABEL_48;
      }
    }
    else
    {
      if( v6 == 10 )
      {
        p_Xmm7 = L"Control\\DeviceContainers";
        goto LABEL_48;
      }
      v15 = (unsigned int)(v6 - 5);
      if( v6 == 5 )
      {
        p_Xmm7 = (const wchar_t *)&stru_1407D01E0.Xmm7;
        EnumSecurityDescriptor = PnpGetEnumSecurityDescriptor(v15, (__int64)a2, a3);
        if( !EnumSecurityDescriptor )
          return(unsigned int)-1073741595;
LABEL_48:
        Tree = SysCtxGetCachedContextBaseKey((_QWORD *)a2[7], v9, &v34);
        if( Tree >= 0 )
        {
          Tree = SysCtxRegCreateTree(a2[7], v34, p_Xmm7, 0, 0x2000000u, 0i64, v32, (__int64)&v33, 0i64);
          if( Tree >= 0 )
          {
            if( v6 > 10 )
            {
              v27 = v6 - 11;
              if( !v27 )
              {
                v26 = v33;
                a2[14] = v33;
                goto LABEL_61;
              }
              v28 = v27 - 1;
              if( !v28 )
              {
                v26 = v33;
                a2[15] = v33;
                goto LABEL_61;
              }
              v29 = v28 - 1;
              if( !v29 )
              {
                v26 = v33;
                a2[16] = v33;
                goto LABEL_61;
              }
              v31 = v29 - 1;
              if( !v31 )
              {
                v26 = v33;
                a2[17] = v33;
                goto LABEL_61;
              }
              if( v31 == 1 )
              {
                v26 = v33;
                a2[18] = v33;
                goto LABEL_61;
              }
            }
            else
            {
              if( v6 == 10 )
              {
                v26 = v33;
                a2[13] = v33;
                goto LABEL_61;
              }
              v22 = v6 - 5;
              if( !v22 )
              {
                v26 = v33;
                a2[8] = v33;
                goto LABEL_61;
              }
              v23 = v22 - 1;
              if( !v23 )
              {
                v26 = v33;
                a2[9] = v33;
                goto LABEL_61;
              }
              v24 = v23 - 1;
              if( !v24 )
              {
                v26 = v33;
                a2[10] = v33;
                goto LABEL_61;
              }
              v25 = v24 - 1;
              if( !v25 )
              {
                v26 = v33;
                a2[11] = v33;
LABEL_61:
                *v35 = v26;
                goto LABEL_62;
              }
              if( v25 == 1 )
              {
                v26 = v33;
                a2[12] = v33;
                goto LABEL_61;
              }
            }
            Tree = -1073741811;
          }
        }
LABEL_62:
        if( EnumSecurityDescriptor )
          ExFreePoolWithTag(EnumSecurityDescriptor, 0);
        return(unsigned int)Tree;
      }
      v16 = v15 - v10;
      if( !v16 )
      {
        p_Xmm7 = L"Services";
        goto LABEL_48;
      }
      v17 = v16 - v10;
      if( !v17 )
      {
        p_Xmm7 = L"Control\\Class";
        goto LABEL_48;
      }
      v18 = v17 - v10;
      if( !v18 )
      {
        p_Xmm7 = L"Control\\DeviceClasses";
        goto LABEL_48;
      }
      if( v18 == v10 )
      {
        p_Xmm7 = L"Control\\DeviceInterfaces";
        if( !*(_BYTE *)(v8 + 4) )
          p_Xmm7 = L"Control\\DeviceClasses";
        goto LABEL_48;
      }
    }
    return(unsigned int)-1073741811;
  }
  return(unsigned int)Tree;
}

Referenced by:

PipOpenServiceEnumKeys
PnpCtxGetCachedContextBaseKey
PnpCtxOpenContextNodeBaseKey