RtlpNewSecurityObject

INT64 __fastcall RtlpNewSecurityObject(
        VOID *ParentDescriptor,
        VOID *CreatorDescriptor,
        VOID **NewDescriptor,
        _GUID **pObjectType,
        UINT64 GuidCount,
        UINT8 IsDirectoryObject,
        UINT64 AutoInheritFlags,
        VOID *Token,
        _GENERIC_MAPPING *GenericMapping,
        _SECURITY_OBJECT_AI_PARAMS *AutoInheritParams){
  int v10; 
  __int128 *v11; 
  _DWORD *v12; 
  unsigned int *v13; 
  UINT8 *v14; 
  char *v15; 
  UINT8 *v16; 
  int v17; 
  char *v18; 
  __int16 v19; 
  bool v20; 
  _ETHREAD *CurrentThread; 
  __int64 v22; 
  INT64 v23; 
  INT64 v24; 
  UINT8 *v25; 
  __int64 v26; 
  UINT8 *v27; 
  __int64 v28; 
  __int64 v29; 
  UINT8 *v30; 
  UINT8 *v31; 
  UINT8 **TokenIntegrity; 
  UINT8 *v33; 
  UINT8 *v34; 
  UINT8 *v35; 
  __int64 v36; 
  __int64 v37; 
  __int64 v38; 
  __int64 v39; 
  void *PoolWithTag; 
  UINT64 v41; 
  char *v42; 
  __int64 v43; 
  UINT8 *v44; 
  __int64 v45; 
  __int16 v46; 
  char *v47; 
  char *v48; 
  UINT8 *v49; 
  UINT8 *v50; 
  bool v51; 
  int v52; 
  char v53; 
  int v54; 
  int v55; 
  int v56; 
  unsigned __int8 *v57; 
  unsigned __int8 *v58; 
  int v59; 
  __int16 v60; 
  int v61; 
  bool v62; 
  __int16 v63; 
  int v64; 
  int v65; 
  unsigned __int8 *v66; 
  unsigned __int8 *v67; 
  int v68; 
  char *v69; 
  __int16 v70; 
  PVOID v71; 
  __int16 v72; 
  ACL *v73; 
  __int64 v74; 
  INT64 *v75; 
  __int64 v76; 
  unsigned int v77; 
  int v78; 
  __int64 v79; 
  UINT8 *v80; 
  __int16 v81; 
  ACL *v82; 
  __int64 v83; 
  INT64 *v84; 
  __int64 v85; 
  int ServerAcl; 
  int v87; 
  int v88; 
  __int64 v89; 
  unsigned __int8 v90; 
  UINT64 v91; 
  struct _ACL *v92; 
  unsigned __int8 *v93; 
  unsigned int v94; 
  int v95; 
  struct _ACL *v96; 
  _ACL *v97; 
  __int16 v98; 
  struct _ACL *v99; 
  ACL *v100; 
  int v101; 
  int v102; 
  int v103; 
  int v104; 
  ACL *v105; 
  int v106; 
  int v107; 
  int v108; 
  __int64 v109; 
  void *v110; 
  char v111; 
  __int64 v112; 
  int v113; 
  __int16 v114; 
  __int16 v115; 
  unsigned __int8 *v116; 
  unsigned __int8 *v117; 
  int v118; 
  __int16 v119; 
  int v120; 
  int v121; 
  char v122; 
  SECURITY_SUBJECT_CONTEXT *v123; 
  CHAR v124; 
  _ACL *v125; 
  bool v126; 
  int v127; 
  unsigned int v128; 
  unsigned int v129; 
  int v130; 
  unsigned int v131; 
  int v132; 
  unsigned int v133; 
  char *v134; 
  char *v135; 
  __int16 v136; 
  _ACL *v137; 
  bool v138; 
  unsigned __int16 *v139; 
  __int64 v140; 
  unsigned __int16 *v141; 
  char v142; 
  __int64 v143; 
  UINT8 *v144; 
  unsigned int v146; 
  int v147; 
  struct _ACL *v148; 
  __int16 v149; 
  ACL *v150; 
  __int64 v151; 
  __int16 v152; 
  int v153; 
  int v154; 
  int v155; 
  __int16 v156; 
  unsigned int v157; 
  ACL *v158; 
  __int64 v159; 
  __int64 v160; 
  __int64 v161; 
  __int64 v162; 
  __int16 v163; 
  unsigned int v164; 
  __int16 v165; 
  __int64 v166; 
  __int16 v167; 
  __int64 v168; 
  __int16 v169; 
  __int64 v170; 
  unsigned int v171; 
  struct _ACL *v172; 
  char v173; 
  unsigned int v174; 
  unsigned int v175; 
  struct _ACL *v176; 
  _ETHREAD *v177; 
  __int64 v178; 
  __int64 v179; 
  __int64 v180; 
  __int64 v181; 
  __int64 v182; 
  int v183; 
  int v184; 
  __int64 v185; 
  unsigned __int16 *v186; 
  __int64 v187; 
  char *v188; 
  __int64 v189; 
  __int64 v190; 
  char *v191; 
  __int64 v192; 
  __int16 v193; 
  ACL *v194; 
  __int64 v195; 
  __int64 v196; 
  VOID *v197; 
  ULONG ConstraintMask; 
  unsigned int v199; 
  int v200; 
  UINT8 v201; 
  UINT8 v202; 
  UCHAR AceType; 
  UINT64 AceTypea; 
  UINT64 AceTypeb; 
  PSID LabelSid; 
  PGENERIC_MAPPING GenericMappinga; 
  char v208; 
  CHAR AccessMode; 
  bool v210; 
  unsigned __int16 *v211; 
  UINT8 pbDominate[8]; 
  void *Src; 
  char v214; 
  _DWORD v215[3]; 
  UINT8 ServerAclAllocated[8]; 
  char v217; 
  char v218; 
  char v219; 
  _DWORD v220[3]; 
  _WORD pIndex[2]; 
  int pIndex_4; 
  __int64 v223; 
  __int128 *v224; 
  PVOID Owner; 
  int v226; 
  UINT8 *v227; 
  PGENERIC_MAPPING v228; 
  VOID *ServerSid; 
  PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext; 
  int v231; 
  int v232; 
  __int64 v233; 
  VOID *ParentDescriptora; 
  PVOID SecurityDescriptor; 
  ULONG MandatoryFlags[2]; 
  __int64 v237; 
  int v238; 
  int v239; 
  PSID Sid; 
  _GUID **pObjectTypea; 
  PVOID P; 
  struct _ACL *p_Acl; 
  unsigned __int16 *v244; 
  PVOID v245; 
  PVOID v246; 
  DWORD GrantedAccess; 
  INT64 AccessStatus; 
  PVOID TokenTrustLevel; 
  _SECURITY_OBJECT_AI_PARAMS *v250; 
  UINT64 pSaclSecurityInformation; 
  __int64 v252; 
  VOID **v253; 
  __int128 v254[2]; 
  __int64 v255; 
  int v256; 
  unsigned __int16 v257; 
  struct _PRIVILEGE_SET RequiredPrivileges; 
  struct _ACL Acl; 
  INT64 result[15]; 
  struct _ACL v261; 
  v10 = 0;
  v228 = GenericMapping;
  v11 = (__int128 *)CreatorDescriptor;
  v12 = 0i64;
  v250 = AutoInheritParams;
  v13 = (unsigned int *)ParentDescriptor;
  v253 = NewDescriptor;
  v255 = 0i64;
  v214 = 0;
  v14 = 0i64;
  v218 = 0;
  v15 = 0i64;
  v217 = 0;
  v16 = 0i64;
  v208 = 0;
  ServerAclAllocated[1] = 0;
  ServerAclAllocated[0] = 0;
  pIndex[0] = 0;
  ServerAclAllocated[2] = 0;
  ServerAclAllocated[5] = 0;
  ServerAclAllocated[7] = 0;
  v224 = (__int128 *)CreatorDescriptor;
  v17 = AutoInheritFlags;
  pObjectTypea = pObjectType;
  v18 = 0i64;
  p_Acl = &Acl;
  ParentDescriptora = ParentDescriptor;
  SubjectSecurityContext = (PSECURITY_SUBJECT_CONTEXT)Token;
  v226 = 0;
  v211 = 0i64;
  v245 = 0i64;
  P = 0i64;
  Sid = 0i64;
  TokenTrustLevel = 0i64;
  ServerSid = 0i64;
  v237 = 0i64;
  v244 = 0i64;
  *(_QWORD *)&v215[1] = 0i64;
  AccessMode = 1;
  memset(v220, 0, sizeof(v220));
  HIDWORD(AccessStatus) = 0;
  v252 = 0i64;
  *(_QWORD *)MandatoryFlags = 0i64;
  pSaclSecurityInformation = 0i64;
  SecurityDescriptor = 0i64;
  pbDominate[0] = 1;
  v246 = 0i64;
  v219 = 0;
  memset(v254, 0, sizeof(v254));
  memset(&RequiredPrivileges, 0, sizeof(RequiredPrivileges));
  if( (AutoInheritFlags & 0x2000) == 0 )
    AccessMode = *((_BYTE *)KeGetCurrentThread() + 562);
  if( v11 )
  {
    ServerAclAllocated[4] = 1;
  }
  else
  {
    v11 = v254;
    ServerAclAllocated[4] = 0;
    v224 = v254;
    LOBYTE(v254[0]) = 1;
  }
  v19 = *((_WORD *)v11 + 1);
  v20 = (v19 & 0x80u) != 0;
  v210 = (v19 & 0x80u) != 0;
  ServerAclAllocated[6] = (v19 & 0x40) != 0;
  if( Token || (v19 & 0x80u) != 0 )
  {
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 242);
    LOBYTE(v17) = 1;
    ExAcquireResourceSharedLite(*(PERESOURCE *)(*((_QWORD *)Token + 2) + 48i64), v17);
    v22 = *(_QWORD *)Token;
    if( *(_QWORD *)Token
      && (v177 = (_ETHREAD *)KeGetCurrentThread(),
          --*((_WORD *)v177 + 242),
          LOBYTE(v22) = 1,
          ExAcquireResourceSharedLite(*(PERESOURCE *)(*(_QWORD *)Token + 48i64), v22),
          (v23 = *(_QWORD *)Token) != 0) )
    {
      if( *((_DWORD *)Token + 2) == 1 )
        v210 = 1;
      v24 = *((_QWORD *)Token + 2);
    }
    else
    {
      v23 = *((_QWORD *)Token + 2);
      v24 = v23;
    }
    v25 = *(UINT8 **)(v23 + 168);
    v26 = *(_QWORD *)(v23 + 184);
    v27 = *(UINT8 **)(*(_QWORD *)(v23 + 152) + 16i64 * *(unsigned int *)(v23 + 144));
    v28 = *(_QWORD *)(v24 + 152);
    v29 = *(unsigned int *)(v24 + 144);
    v30 = *(UINT8 **)(v24 + 168);
    v31 = *(UINT8 **)(v28 + 16 * v29);
    TokenIntegrity = (UINT8 **)SepLocateTokenIntegrity(v23);
    if( TokenIntegrity )
      v33 = *TokenIntegrity;
    else
      v33 = (UINT8 *)SepDefaultMandatorySid;
    LODWORD(v34) = SepLocateTokenTrustLevel(SubjectSecurityContext);
    v35 = v34;
    if( v34 )
      v36 = 4i64 * v34[1] + 8;
    else
      v36 = 0i64;
    if( v25 )
      v37 = 4i64 * v25[1] + 8;
    else
      v37 = 0i64;
    if( v30 )
      v38 = 4i64 * v30[1] + 32;
    else
      v38 = 24i64;
    if( v26 )
      v39 = *(unsigned __int16 *)(v26 + 2);
    else
      v39 = 0i64;
    PoolWithTag = ExAllocatePoolWithTag(
                    PagedPool,
                    v38 + v39 + v37 + v36 + 4 * (v33[1] + v27[1] + (unsigned __int64)v31[1]),
                    0x64536553ui64);
    P = PoolWithTag;
    if( !PoolWithTag )
    {
      SeUnlockSubjectContext(SubjectSecurityContext);
      return 3221225626i64;
    }
    memmove((UINT8 *)PoolWithTag, v27, 4i64 * v27[1] + 8);
    v41 = 4i64 * v33[1] + 8;
    v42 = (char *)P + 4 * v27[1] + 8;
    Sid = v42;
    memmove((UINT8 *)v42, v33, v41);
    v43 = v33[1];
    v15 = &v42[4 * v43 + 8];
    ServerSid = v15;
    if( v35 )
    {
      v162 = v35[1];
      TokenTrustLevel = &v42[4 * v43 + 8];
      memmove((UINT8 *)TokenTrustLevel, v35, 4 * v162 + 8);
      v15 += 4 * v35[1] + 8;
      ServerSid = v15;
    }
    else
    {
      TokenTrustLevel = 0i64;
    }
    if( v25 )
    {
      v14 = (UINT8 *)v15;
      memmove((UINT8 *)v15, v25, 4i64 * v25[1] + 8);
      v15 += 4 * v25[1] + 8;
      ServerSid = v15;
    }
    else
    {
      v14 = 0i64;
    }
    memmove((UINT8 *)v15, v31, 4i64 * v31[1] + 8);
    v44 = (UINT8 *)&v15[4 * v31[1] + 8];
    v244 = (unsigned __int16 *)v44;
    if( v30 )
    {
      v45 = v30[1];
      v237 = (__int64)v44;
      v16 = v44;
      memmove(v44, v30, 4 * v45 + 8);
      v44 += 4 * v30[1] + 8;
      v244 = (unsigned __int16 *)v44;
    }
    else
    {
      v16 = 0i64;
      v237 = 0i64;
    }
    if( v26 )
      memmove(v44, (UINT8 *)v26, *(unsigned __int16 *)(v26 + 2));
    else
      v244 = 0i64;
    ExReleaseResourceLite(*((PERESOURCE *)SubjectSecurityContext->PrimaryToken + 6));
    KeLeaveCriticalRegion();
    if( SubjectSecurityContext->ClientToken )
    {
      ExReleaseResourceLite(*((PERESOURCE *)SubjectSecurityContext->ClientToken + 6));
      KeLeaveCriticalRegion();
    }
    v20 = v210;
    v10 = 0;
    v13 = (unsigned int *)ParentDescriptora;
    v18 = (char *)P;
    LOBYTE(v17) = AutoInheritFlags;
    v11 = v224;
    v12 = *(_DWORD **)&v215[1];
  }
  v46 = *((_WORD *)v11 + 1);
  if( v46 < 0 )
  {
    v159 = *((unsigned int *)v11 + 1);
    if( !(_DWORD)v159 )
      goto LABEL_33;
    v47 = (char *)v11 + v159;
  }
  else
  {
    v47 = (char *)*((_QWORD *)v11 + 1);
  }
  Owner = v47;
  if( v47 )
  {
    ServerAclAllocated[1] = 1;
    goto LABEL_37;
  }
LABEL_33:
  if( (v17 & 0x20) != 0 )
  {
    if( !v13 )
    {
      v141 = 0i64;
      ServerAcl = -1073741734;
      v139 = 0i64;
      goto LABEL_501;
    }
    if( *((__int16 *)v13 + 1) >= 0 )
    {
      v188 = (char *)*((_QWORD *)v13 + 1);
    }
    else
    {
      v187 = v13[1];
      if( !(_DWORD)v187 )
        goto LABEL_377;
      v188 = (char *)v13 + v187;
    }
    Owner = v188;
    ServerAclAllocated[1] = 1;
    if( v188 )
      goto LABEL_37;
LABEL_377:
    v141 = 0i64;
    ServerAcl = -1073741734;
    v139 = 0i64;
    goto LABEL_501;
  }
  v48 = v15;
  if( !v20 )
    v48 = v18;
  Owner = v48;
  if( !v48 )
  {
    v141 = 0i64;
    ServerAcl = -1073741700;
    v139 = 0i64;
    goto LABEL_501;
  }
LABEL_37:
  if( v46 < 0 )
  {
    v160 = *((unsigned int *)v11 + 2);
    if( !(_DWORD)v160 )
      goto LABEL_40;
    v49 = (UINT8 *)v11 + v160;
  }
  else
  {
    v49 = (UINT8 *)*((_QWORD *)v11 + 2);
  }
  v227 = v49;
  if( v49 )
    goto LABEL_44;
LABEL_40:
  if( (v17 & 0x40) != 0 )
  {
    if( !v13 )
    {
      v141 = 0i64;
      ServerAcl = -1073741733;
      v139 = 0i64;
      goto LABEL_501;
    }
    if( *((__int16 *)v13 + 1) >= 0 )
    {
      v50 = (UINT8 *)*((_QWORD *)v13 + 2);
    }
    else
    {
      v189 = v13[2];
      if( !(_DWORD)v189 )
        goto LABEL_385;
      v50 = (UINT8 *)v13 + v189;
    }
  }
  else
  {
    v50 = v14;
    if( v20 )
      v50 = v16;
  }
  v227 = v50;
  if( !v50 )
  {
LABEL_385:
    v141 = 0i64;
    ServerAcl = -1073741733;
    v139 = 0i64;
    goto LABEL_501;
  }
LABEL_44:
  LODWORD(v223) = v17 & 4;
  v51 = (v17 & 4) != 0;
  v52 = v17 & 2;
  v53 = v52 != 0;
  ServerAclAllocated[3] = v52 != 0;
  if( (v46 & 0x20) != 0 )
    v10 = 8;
  v54 = 0;
  if( (v46 & 0x800) != 0 )
    v55 = 1024;
  else
    v55 = 0;
  if( (v46 & 0x2000) != 0 )
    v56 = 4096;
  else
    v56 = 0;
  if( (v46 & 0x10) != 0 )
  {
    if( v46 >= 0 )
    {
      v57 = (unsigned __int8 *)*((_QWORD *)v11 + 3);
    }
    else
    {
      v179 = *((unsigned int *)v11 + 3);
      if( (_DWORD)v179 )
        v57 = (unsigned __int8 *)v11 + v179;
      else
        v57 = 0i64;
    }
  }
  else
  {
    v57 = 0i64;
  }
  if( !v13 )
    goto LABEL_53;
  v163 = *((_WORD *)v13 + 1);
  if( (v163 & 0x10) == 0 )
    goto LABEL_53;
  if( v163 < 0 )
  {
    v164 = v13[3];
    if( v164 )
    {
      v58 = (unsigned __int8 *)ParentDescriptora + v164;
      goto LABEL_54;
    }
LABEL_53:
    v58 = 0i64;
    goto LABEL_54;
  }
  v58 = (unsigned __int8 *)*((_QWORD *)v13 + 3);
LABEL_54:
  v59 = v10 | v55 | v56 | ((v46 & 0x10) != 0 ? 4 : 0);
  if( !v59 && !v58 )
  {
    v220[0] = v52 != 0 ? 0x400 : 0;
    Src = 0i64;
    goto LABEL_57;
  }
  v171 = 200;
  v215[0] = 200;
  while( 1 )
  {
    v172 = (struct _ACL *)ExAllocatePoolWithTag(PagedPool, v171, 0x63416553ui64);
    Src = v172;
    if( !v172 )
    {
      v139 = 0i64;
      goto LABEL_498;
    }
    ServerAcl = RtlpInheritAcl2(
                  v58,
                  v57,
                  v59,
                  IsDirectoryObject,
                  v53,
                  v51,
                  (__int64)Owner,
                  (__int64)v227,
                  (__int64)ServerSid,
                  v237,
                  v228,
                  2,
                  (__int64)pObjectTypea,
                  GuidCount,
                  (__int64)v215,
                  v172,
                  (__int64)ServerAclAllocated,
                  (__int64)v220);
    if( ServerAcl >= 0 )
      break;
    ExFreePoolWithTag(Src, 0);
    Src = 0i64;
    if( ServerAcl != -1073741789 )
      goto LABEL_279;
    if( (unsigned int)++v54 >= 2 )
      goto LABEL_279;
    v171 = v215[0];
    v53 = ServerAclAllocated[3];
  }
  if( !v215[0] )
  {
    ExFreePoolWithTag(Src, 0);
    Src = 0i64;
  }
LABEL_279:
  if( ServerAcl >= 0 )
  {
    v214 = 1;
    v183 = 32784;
    if( (v220[0] & 8) != 0 )
      v183 = 32816;
    if( (v220[0] & 0x1000) != 0 )
      v184 = 0x2000;
    else
      v184 = 0;
    v11 = v224;
    v215[0] = v183 | v184 | (2 * (v220[0] & 0x400));
    goto LABEL_60;
  }
  if( ServerAcl != -2147483637 )
    goto LABEL_423;
  v11 = v224;
LABEL_57:
  v60 = *((_WORD *)v11 + 1);
  v61 = 34816;
  if( !v52 )
    v61 = 0x8000;
  v215[0] = v61;
  if( (v60 & 0x30) == 48 )
  {
    if( (v60 & 0x10) == 0 )
    {
      Src = 0i64;
LABEL_403:
      ServerAclAllocated[0] = 1;
      v215[0] = v61 | v60 & 0x2000 | 0x10;
      goto LABEL_60;
    }
    if( v60 >= 0 )
    {
      v191 = (char *)*((_QWORD *)v11 + 3);
    }
    else
    {
      v190 = *((unsigned int *)v11 + 3);
      if( !(_DWORD)v190 )
      {
        Src = 0i64;
        goto LABEL_403;
      }
      v191 = (char *)v11 + v190;
    }
    Src = v191;
    goto LABEL_403;
  }
LABEL_60:
  v62 = (_DWORD)v223 != 0;
  v63 = *((_WORD *)v11 + 1);
  if( (v63 & 0x20) != 0 )
    v64 = 8;
  else
    v64 = 0;
  if( (v63 & 0x800) != 0 )
    v65 = 1024;
  else
    v65 = 0;
  if( (v63 & 0x10) != 0 )
  {
    if( v63 >= 0 )
    {
      v66 = (unsigned __int8 *)*((_QWORD *)v11 + 3);
    }
    else
    {
      v180 = *((unsigned int *)v11 + 3);
      if( (_DWORD)v180 )
        v66 = (unsigned __int8 *)v11 + v180;
      else
        v66 = 0i64;
    }
  }
  else
  {
    v66 = 0i64;
  }
  if( !ParentDescriptora )
    goto LABEL_67;
  v165 = *((_WORD *)ParentDescriptora + 1);
  if( (v165 & 0x10) == 0 )
    goto LABEL_67;
  if( v165 >= 0 )
  {
    v67 = (unsigned __int8 *)*((_QWORD *)ParentDescriptora + 3);
    goto LABEL_68;
  }
  v166 = *((unsigned int *)ParentDescriptora + 3);
  if( (_DWORD)v166 )
    v67 = (unsigned __int8 *)ParentDescriptora + v166;
  else
LABEL_67:
    v67 = 0i64;
LABEL_68:
  v68 = v64 | v65 | ((*((_WORD *)v11 + 1) & 0x10) != 0 ? 4 : 0);
  if( !v68 && !v67 )
  {
    v69 = 0i64;
    *(_QWORD *)&v220[1] = 0i64;
    v239 = -2147483637;
    goto LABEL_71;
  }
  v173 = ServerAclAllocated[3];
  v174 = 200;
  v231 = 200;
  v175 = 0;
  while( 1 )
  {
    v176 = (struct _ACL *)ExAllocatePoolWithTag(PagedPool, v174, 0x63416553ui64);
    *(_QWORD *)&v220[1] = v176;
    if( !v176 )
      goto LABEL_496;
    ServerAcl = RtlpInheritAcl2(
                  v67,
                  v66,
                  v68,
                  IsDirectoryObject,
                  v173,
                  v62,
                  (__int64)Owner,
                  (__int64)v227,
                  (__int64)ServerSid,
                  v237,
                  v228,
                  2,
                  (__int64)pObjectTypea,
                  GuidCount,
                  (__int64)&v231,
                  v176,
                  (__int64)pIndex,
                  (__int64)&AccessStatus + 4);
    if( ServerAcl >= 0 )
      break;
    ExFreePoolWithTag(*(PVOID *)&v220[1], 0);
    *(_QWORD *)&v220[1] = 0i64;
    if( ServerAcl != -1073741789 || (++v175, v175 >= 2) )
    {
      v69 = 0i64;
      goto LABEL_287;
    }
    v174 = v231;
  }
  if( v231 )
  {
    v69 = *(char **)&v220[1];
  }
  else
  {
    ExFreePoolWithTag(*(PVOID *)&v220[1], 0);
    v69 = 0i64;
    *(_QWORD *)&v220[1] = 0i64;
  }
LABEL_287:
  v239 = ServerAcl;
  if( ServerAcl >= 0 )
  {
    v11 = v224;
    v218 = 1;
    goto LABEL_72;
  }
  if( ServerAcl != -2147483637 )
    goto LABEL_423;
  v11 = v224;
LABEL_71:
  v70 = *((_WORD *)v11 + 1);
  if( (v70 & 0x30) == 48 )
  {
    if( (v70 & 0x10) == 0 )
    {
      v69 = 0i64;
      *(_QWORD *)&v220[1] = 0i64;
      goto LABEL_72;
    }
    if( v70 >= 0 )
    {
      v69 = (char *)*((_QWORD *)v11 + 3);
    }
    else
    {
      v192 = *((unsigned int *)v11 + 3);
      if( !(_DWORD)v192 )
      {
        v69 = 0i64;
        *(_QWORD *)&v220[1] = 0i64;
        goto LABEL_72;
      }
      v69 = (char *)v11 + v192;
    }
    *(_QWORD *)&v220[1] = v69;
  }
LABEL_72:
  v71 = TokenTrustLevel;
  pIndex_4 = 0;
  while( 2 )
  {
    v72 = *((_WORD *)v11 + 1);
    if( (v72 & 0x10) != 0 )
    {
      if( v72 >= 0 )
      {
        v73 = (ACL *)*((_QWORD *)v11 + 3);
      }
      else
      {
        v178 = *((unsigned int *)v11 + 3);
        if( (_DWORD)v178 )
          v73 = (ACL *)((char *)v11 + v178);
        else
          v73 = 0i64;
      }
    }
    else
    {
      v73 = 0i64;
    }
    LODWORD(v74) = RtlFindAceByType(v73, 0x14ui64, (UINT64 *)&pIndex_4);
    v76 = v74;
    if( v74 && v74 != -8 && !RtlpValidTrustSubjectContext(v71, (PVOID)(v74 + 8), v75) )
    {
LABEL_422:
      ServerAcl = -1073741790;
      goto LABEL_423;
    }
    ++pIndex_4;
    if( v76 )
    {
      v11 = v224;
      continue;
    }
    break;
  }
  v77 = AutoInheritFlags;
  v78 = 4;
  v79 = (__int64)v224;
  if( (AutoInheritFlags & 0x800) == 0 )
  {
LABEL_78:
    v80 = v227;
    v246 = v69;
    goto LABEL_79;
  }
  pIndex_4 = 0;
  do
  {
    v193 = *(_WORD *)(v79 + 2);
    if( (v193 & 0x10) != 0 )
    {
      if( v193 >= 0 )
      {
        v194 = *(ACL **)(v79 + 24);
      }
      else
      {
        v195 = *(unsigned int *)(v79 + 12);
        if( (_DWORD)v195 )
          v194 = (ACL *)(v79 + v195);
        else
          v194 = 0i64;
      }
    }
    else
    {
      v194 = 0i64;
    }
    LODWORD(v196) = RtlFindAceByType(v194, 0x14ui64, (UINT64 *)&pIndex_4);
    ++pIndex_4;
    if( !v196 )
    {
      if( v71 )
      {
        if( !v250 )
        {
          v139 = (unsigned __int16 *)Src;
          ServerAcl = -1073741811;
          goto LABEL_499;
        }
        ConstraintMask = v250->ConstraintMask;
        v197 = v71;
        v199 = 0;
        goto LABEL_442;
      }
      goto LABEL_78;
    }
  }
  while( (*(_BYTE *)(v196 + 1) & 8) != 0 );
  v197 = (VOID *)(v196 + 8);
  ConstraintMask = *(_DWORD *)(v196 + 4);
  v199 = *(unsigned __int8 *)(v196 + 1);
  if( !v250 || (ConstraintMask & v250->ConstraintMask) != ConstraintMask || v196 == -8 )
  {
LABEL_437:
    v139 = (unsigned __int16 *)Src;
    ServerAcl = -1073741811;
    goto LABEL_499;
  }
LABEL_442:
  ServerAcl = RtlCreateAcl(&v261, 0x58u, 2u);
  if( ServerAcl < 0
    || (LODWORD(LabelSid) = ConstraintMask,
        ServerAcl = RtlAddProcessTrustLabelAce(&v261, 2ui64, v199, v197, 0x14u, (UINT64)LabelSid),
        ServerAcl < 0)
    || (v79 = (__int64)v224,
        v80 = v227,
        ServerAcl = RtlpComputeMergedAcl(
                      *(_BYTE **)&v220[1],
                      (*((_WORD *)v224 + 1) & 0x800 | (*((unsigned __int16 *)v224 + 1) >> 1) & 0x18u) >> 1,
                      (unsigned __int8 *)&v261,
                      4,
                      (__int64)Owner,
                      (__int64)v227,
                      (__int64)v228,
                      2,
                      (__int64)&v246,
                      (__int64)v220),
        ServerAcl < 0) )
  {
LABEL_423:
    v139 = (unsigned __int16 *)Src;
LABEL_499:
    v141 = v211;
LABEL_500:
    v12 = *(_DWORD **)&v215[1];
LABEL_501:
    v142 = 0;
    goto LABEL_186;
  }
  v77 = AutoInheritFlags;
  v219 = 1;
LABEL_79:
  v81 = *(_WORD *)(v79 + 2);
  if( (v81 & 0x10) != 0 )
  {
    if( v81 >= 0 )
    {
      v82 = *(ACL **)(v79 + 24);
    }
    else
    {
      v181 = *(unsigned int *)(v79 + 12);
      if( (_DWORD)v181 )
        v82 = (ACL *)(v79 + v181);
      else
        v82 = 0i64;
    }
  }
  else
  {
    v82 = 0i64;
  }
  v238 = 0;
  v256 = 0;
  v257 = 256;
  v232 = 0;
  while( 2 )
  {
    LODWORD(v83) = RtlFindAceByType(v82, 0x15ui64, (UINT64 *)&v232);
    v85 = v83;
    if( !v83 )
      goto LABEL_83;
    if( (*(_DWORD *)(v83 + 4) & 0xFF000000) != 0 )
      goto LABEL_437;
    if( (*(_BYTE *)(v83 + 1) & 0x40) != 0 )
    {
      if( !RtlpValidTrustSubjectContext(v71, (PVOID)(v83 + 8), v84) )
        goto LABEL_422;
      goto LABEL_83;
    }
    v200 = *(_DWORD *)(v83 + 10) - v256;
    if( !v200 )
      v200 = *(unsigned __int16 *)(v83 + 14) - v257;
    if( v200 )
      goto LABEL_437;
    if( *(_BYTE *)(v83 + 9) == 1 && !*(_DWORD *)(v83 + 16) )
    {
LABEL_83:
      ++v232;
      if( !v85 )
      {
        ServerAcl = v238;
        goto LABEL_85;
      }
      continue;
    }
    break;
  }
  ServerAcl = -1073741811;
LABEL_85:
  if( ServerAcl < 0 )
    goto LABEL_482;
  v87 = (v77 >> 8) & 1 | 2;
  if( (v77 & 0x200) == 0 )
    v87 = (v77 >> 8) & 1;
  v88 = v87 | 4;
  if( (v77 & 0x400) == 0 )
    v88 = v87;
  if( v88 )
  {
    v89 = v252;
    goto LABEL_92;
  }
  v149 = *(_WORD *)(v79 + 2);
  if( (v149 & 0x10) != 0 )
  {
    if( v149 >= 0 )
    {
      v150 = *(ACL **)(v79 + 24);
    }
    else
    {
      v182 = *(unsigned int *)(v79 + 12);
      if( (_DWORD)v182 )
        v150 = (ACL *)(v79 + v182);
      else
        v150 = 0i64;
    }
  }
  else
  {
    v150 = 0i64;
  }
  LODWORD(v151) = RtlFindAceByType(v150, 0x11ui64, 0i64);
  v89 = v151;
  if( v151 )
  {
    v90 = *(_BYTE *)(v151 + 1);
    v88 = *(_DWORD *)(v151 + 4);
    *(_QWORD *)MandatoryFlags = v151 + 8;
    if( v90 == 8 || (v90 & 0x10) != 0 )
    {
      v89 = 0i64;
      *(_QWORD *)MandatoryFlags = 0i64;
      v88 = 0;
      goto LABEL_92;
    }
  }
  else
  {
LABEL_92:
    v90 = 0;
  }
  if( (v90 & 8) != 0 && *RtlSubAuthoritySid(Sid, 0i64) < 0x2000 )
  {
    v139 = (unsigned __int16 *)Src;
    ServerAcl = -1073740730;
    goto LABEL_499;
  }
  if( v88 )
  {
LABEL_95:
    if( !v89 )
    {
      if( !SubjectSecurityContext )
      {
        v139 = (unsigned __int16 *)Src;
        ServerAcl = -1073741700;
        goto LABEL_499;
      }
      *(_QWORD *)MandatoryFlags = Sid;
      v90 = 0;
    }
  }
  else if( Sid && *RtlSubAuthoritySid(Sid, 0i64) < 0x2000 )
  {
    v88 = 1;
    goto LABEL_95;
  }
  if( !*(_QWORD *)MandatoryFlags )
  {
    v92 = 0i64;
    p_Acl = 0i64;
LABEL_101:
    if( (v77 & 0x700) == 0 )
    {
      if( !v89 && v92 )
      {
        v78 = 0;
      }
      else
      {
        v152 = *(_WORD *)(v79 + 2);
        if( (v152 & 0x20) != 0 )
          v153 = 8;
        else
          v153 = 0;
        if( (v152 & 0x800) != 0 )
          v154 = 1024;
        else
          v154 = 0;
        if( (v152 & 0x2000) != 0 )
          v155 = 4096;
        else
          v155 = 0;
        v78 = v153 | (*(unsigned __int16 *)(v79 + 2) >> 2) & 4 | v154 | v155;
      }
    }
    if( ParentDescriptora )
    {
      v167 = *((_WORD *)ParentDescriptora + 1);
      if( (v167 & 0x10) != 0 )
      {
        if( v167 >= 0 )
        {
          v93 = (unsigned __int8 *)*((_QWORD *)ParentDescriptora + 3);
LABEL_104:
          if( !v78 && !v93 )
          {
LABEL_206:
            v99 = p_Acl;
            v97 = p_Acl;
            v220[0] = 0;
            v98 = 0;
LABEL_113:
            v100 = (ACL *)Src;
            v101 = RtlpCombineAcls(
                     (_ACL *)Src,
                     v97,
                     *(_ACL **)&v220[1],
                     *(_ACL **)&v220[1],
                     (_ACL *)v246,
                     *(_ACL ***)&v220[1],
                     &pSaclSecurityInformation);
            v102 = v215[0];
            ServerAcl = v101;
            if( (v215[0] & 0x2000) != 0 )
              v103 = 0x40000000;
            else
              v103 = 0;
            v104 = v103 | v226;
            if( v97 && v97 != v99 )
              ExFreePoolWithTag(v97, 0);
            if( ServerAcl < 0 )
              goto LABEL_423;
            v105 = (ACL *)pSaclSecurityInformation;
            if( pSaclSecurityInformation )
            {
              if( v214 && Src )
                ExFreePoolWithTag(Src, 0);
              Src = v105;
              v100 = v105;
              v217 = 1;
              if( (v98 & 8) != 0 )
                v106 = 48;
              else
                v106 = 16;
              if( (v98 & 0x1000) != 0 )
                v107 = 0x2000;
              else
                v107 = 0;
              v102 |= v106 | (2 * (v98 & 0x400)) | v107;
              v215[0] = v102;
            }
            v108 = AutoInheritFlags;
            v226 = AutoInheritFlags & 8;
            if( (AutoInheritFlags & 8) == 0 )
            {
              LODWORD(v109) = RtlFindAceByType(v100, 0x11ui64, 0i64);
              if( v109 )
                v110 = (void *)(v109 + 8);
              else
                v110 = *(void **)MandatoryFlags;
              if( v110 )
              {
                if( !SubjectSecurityContext )
                {
                  v139 = (unsigned __int16 *)Src;
                  ServerAcl = -1073741700;
                  goto LABEL_499;
                }
                ServerAcl = RtlSidDominates(Sid, v110, pbDominate);
                if( ServerAcl < 0 )
                  goto LABEL_482;
                v108 = AutoInheritFlags;
                if( !pbDominate[0] )
                  ServerAclAllocated[5] = 1;
              }
              else
              {
                v108 = AutoInheritFlags;
              }
            }
            v111 = (_DWORD)v223 != 0;
            v112 = (__int64)v224;
            v113 = v108 & 1;
            pbDominate[0] = (_DWORD)v223 != 0;
            v114 = *((_WORD *)v224 + 1);
            v115 = v114;
            if( (v114 & 4) != 0 )
            {
              if( v114 >= 0 )
              {
                v116 = (unsigned __int8 *)*((_QWORD *)v224 + 4);
              }
              else
              {
                v161 = *((unsigned int *)v224 + 4);
                if( (_DWORD)v161 )
                  v116 = (unsigned __int8 *)v224 + v161;
                else
                  v116 = 0i64;
              }
            }
            else
            {
              v116 = 0i64;
            }
            if( !ParentDescriptora )
              goto LABEL_137;
            v169 = *((_WORD *)ParentDescriptora + 1);
            if( (v169 & 4) == 0 )
              goto LABEL_137;
            if( v169 >= 0 )
            {
              v117 = (unsigned __int8 *)*((_QWORD *)ParentDescriptora + 4);
              goto LABEL_138;
            }
            v170 = *((unsigned int *)ParentDescriptora + 4);
            if( (_DWORD)v170 )
              v117 = (unsigned __int8 *)ParentDescriptora + v170;
            else
LABEL_137:
              v117 = 0i64;
LABEL_138:
            v118 = v115 & 0x140C;
            if( v118 || v117 )
            {
              v146 = 200;
              v147 = 0;
              LODWORD(v223) = 200;
              while( 1 )
              {
                v148 = (struct _ACL *)ExAllocatePoolWithTag(PagedPool, v146, 0x63416553ui64);
                v211 = (unsigned __int16 *)v148;
                if( !v148 )
                {
                  v139 = (unsigned __int16 *)Src;
                  ServerAcl = -1073741801;
                  v141 = 0i64;
                  goto LABEL_500;
                }
                ServerAcl = RtlpInheritAcl2(
                              v117,
                              v116,
                              v118,
                              IsDirectoryObject,
                              v113,
                              v111,
                              (__int64)Owner,
                              (__int64)v227,
                              (__int64)ServerSid,
                              v237,
                              v228,
                              1,
                              (__int64)pObjectTypea,
                              GuidCount,
                              (__int64)&v223,
                              v148,
                              (__int64)&ServerAclAllocated[2],
                              (__int64)v220);
                if( ServerAcl >= 0 )
                  break;
                ExFreePoolWithTag(v211, 0);
                v211 = 0i64;
                if( ServerAcl != -1073741789 )
                  goto LABEL_203;
                if( (unsigned int)++v147 >= 2 )
                  goto LABEL_203;
                v146 = v223;
                v111 = pbDominate[0];
              }
              if( !(_DWORD)v223 )
              {
                ExFreePoolWithTag(v211, 0);
                v211 = 0i64;
              }
LABEL_203:
              if( ServerAcl >= 0 )
              {
                v122 = 1;
                v108 = AutoInheritFlags;
                v208 = 1;
                v121 = v220[0] & 0x1408 | 4 | v215[0];
                v215[0] = v121;
                goto LABEL_148;
              }
              if( ServerAcl == -2147483637 )
              {
                v102 = v215[0];
                v112 = (__int64)v224;
                v108 = AutoInheritFlags;
                goto LABEL_141;
              }
              goto LABEL_423;
            }
            v211 = 0i64;
LABEL_141:
            v119 = *(_WORD *)(v112 + 2);
            v120 = v102 | 0x400;
            if( !v113 )
              v120 = v102;
            if( (*(_WORD *)(v112 + 2) & 0xC) != 12 )
            {
              v121 = v120;
              v215[0] = v120;
              if( !v244 )
              {
LABEL_147:
                v122 = 0;
LABEL_148:
                v123 = SubjectSecurityContext;
                if( (v108 & 0x1000) == 0 && ServerAclAllocated[4] && SubjectSecurityContext && ParentDescriptora )
                {
                  LODWORD(GenericMappinga) = v108 | 1;
                  GrantedAccess = 0;
                  LODWORD(AccessStatus) = 0;
                  LODWORD(AceTypea) = GuidCount;
                  ServerAcl = RtlpNewSecurityObject(
                                ParentDescriptora,
                                0i64,
                                &SecurityDescriptor,
                                pObjectTypea,
                                AceTypea,
                                IsDirectoryObject,
                                (UINT64)GenericMappinga,
                                SubjectSecurityContext,
                                v228,
                                v250);
                  if( ServerAcl < 0 )
                    goto LABEL_482;
                  v156 = *((_WORD *)SecurityDescriptor + 1);
                  if( (v156 & 4) != 0 )
                  {
                    if( v156 >= 0 )
                    {
                      v158 = (ACL *)*((_QWORD *)SecurityDescriptor + 4);
                    }
                    else
                    {
                      v157 = *((_DWORD *)SecurityDescriptor + 4);
                      if( v157 )
                        v158 = (ACL *)((char *)SecurityDescriptor + v157);
                      else
                        v158 = 0i64;
                    }
                  }
                  else
                  {
                    v158 = 0i64;
                  }
                  v124 = AccessMode;
                  if( RtlpOwnerAcesPresent(0x10u, v158) )
                  {
                    LODWORD(AceTypeb) = 0;
                    if( !SeAccessCheck(
                            SecurityDescriptor,
                            v123,
                            0,
                            0x40000ui64,
                            AceTypeb,
                            0i64,
                            v228,
                            AccessMode,
                            (UINT64 *)&GrantedAccess,
                            &AccessStatus) )
                    {
                      ServerAcl = -1073741790;
                      goto LABEL_482;
                    }
                  }
                  LOBYTE(v108) = AutoInheritFlags;
                }
                else
                {
                  v124 = AccessMode;
                }
                v125 = (_ACL *)v211;
                if( v113 && !v211 )
                {
                  v121 |= 0x1000u;
                  v215[0] = v121;
                }
                v126 = !v104 || (v104 & 0x1B0) != v104;
                if( v124 == 1 )
                {
                  v127 = v226;
                  if( ServerAclAllocated[0] && !v226 && v126 )
                  {
                    if( !v123 )
                    {
                      ServerAcl = -1073741700;
                      goto LABEL_482;
                    }
                    RequiredPrivileges.Privilege[0].Luid = *(_LUID *)SeSecurityPrivilege;
                    RequiredPrivileges.Privilege[0].Attributes = 0;
                    RequiredPrivileges.PrivilegeCount = 1;
                    RequiredPrivileges.Control = 1;
                    v201 = SePrivilegeCheck(&RequiredPrivileges, v123, 1);
                    SePrivilegedServiceAuditAlarm(0i64, v123, &RequiredPrivileges, v201);
                    if( !v201 )
                    {
                      ServerAcl = -1073741727;
                      goto LABEL_482;
                    }
                    v125 = (_ACL *)v211;
                    LOBYTE(v108) = AutoInheritFlags;
                  }
                  if( ServerAclAllocated[5] && !v127 )
                  {
                    if( !v123 )
                    {
                      ServerAcl = -1073741700;
                      goto LABEL_482;
                    }
                    RequiredPrivileges.Privilege[0].Luid = (_LUID)SeRelabelPrivilege;
                    RequiredPrivileges.PrivilegeCount = 1;
                    RequiredPrivileges.Control = 1;
                    RequiredPrivileges.Privilege[0].Attributes = 0;
                    v202 = SePrivilegeCheck(&RequiredPrivileges, v123, 1);
                    SePrivilegedServiceAuditAlarm(0i64, v123, &RequiredPrivileges, v202);
                    if( !v202 )
                    {
                      ServerAcl = -1073741727;
                      goto LABEL_482;
                    }
                    v125 = (_ACL *)v211;
                    LOBYTE(v108) = AutoInheritFlags;
                  }
                  if( ServerAclAllocated[1] && (v108 & 0x10) == 0 && !SepValidOwnerSubjectContext(v123, Owner, v210) )
                  {
                    ServerAcl = -1073741734;
                    goto LABEL_482;
                  }
                  if( ServerAclAllocated[2] && v210 )
                  {
                    ServerAcl = RtlpCreateServerAcl(
                                  v125,
                                  ServerAclAllocated[6],
                                  ServerSid,
                                  (_ACL **)&v245,
                                  &ServerAclAllocated[7]);
                    if( ServerAcl < 0 )
                      goto LABEL_482;
                    if( v122 && v211 )
                      ExFreePoolWithTag(v211, 0);
                    v125 = (_ACL *)v245;
                    v211 = (unsigned __int16 *)v245;
                    v245 = 0i64;
                  }
                }
                v128 = 4 * *((unsigned __int8 *)Owner + 1) + 8;
                if( v227 )
                  v129 = 4 * v227[1] + 8;
                else
                  v129 = 0;
                v130 = v121 & 0x10;
                if( (v121 & 0x10) != 0 && Src )
                  v131 = (*((unsigned __int16 *)Src + 1) + 3) & 0xFFFFFFFC;
                else
                  v131 = 0;
                v132 = v121 & 4;
                if( v132 && v125 )
                  v133 = (v125->AclSize + 3) & 0xFFFFFFFC;
                else
                  v133 = 0;
                v134 = (char *)ExAllocatePoolWithTag(
                                 PagedPool,
                                 v129 + v133 + v131 + 4 * *((unsigned __int8 *)Owner + 1) + 28,
                                 0x64536553ui64);
                *(_QWORD *)&v215[1] = v134;
                v135 = v134;
                if( !v134 )
                {
                  ServerAcl = -1073741670;
                  goto LABEL_482;
                }
                v136 = v215[0];
                v137 = (_ACL *)(v134 + 20);
                *(_OWORD *)v134 = 0i64;
                *((_DWORD *)v134 + 4) = 0;
                *((_WORD *)v134 + 1) |= v136;
                v138 = v130 == 0;
                *v134 = 1;
                v139 = (unsigned __int16 *)Src;
                if( !v138 && Src )
                {
                  memmove((UINT8 *)v137, (UINT8 *)Src, *((unsigned __int16 *)Src + 1));
                  if( !v214 )
                    RtlpApplyAclToObject(v137, v228);
                  v135 = *(char **)&v215[1];
                  *(_DWORD *)(*(_QWORD *)&v215[1] + 12i64) = (_DWORD)v137 - v215[1];
                  v140 = v139[1];
                  if( v131 > (unsigned int)v140 )
                  {
                    memset((INT64)v137 + v140, 0i64);
                    v135 = *(char **)&v215[1];
                  }
                  v137 = (_ACL *)((char *)v137 + v131);
                }
                v138 = v132 == 0;
                v141 = v211;
                if( !v138 )
                {
                  if( v211 )
                  {
                    memmove((UINT8 *)v137, (UINT8 *)v211, v211[1]);
                    v142 = v208;
                    if( !v208 )
                      RtlpApplyAclToObject(v137, v228);
                    *(_DWORD *)(*(_QWORD *)&v215[1] + 16i64) = (_DWORD)v137 - v215[1];
                    v143 = v211[1];
                    if( v133 > (unsigned int)v143 )
                      memset((INT64)v137 + v143, 0i64);
                    v137 = (_ACL *)((char *)v137 + v133);
                    goto LABEL_183;
                  }
                  *((_DWORD *)v135 + 4) = 0;
                }
                v142 = v208;
LABEL_183:
                memmove((UINT8 *)v137, (UINT8 *)Owner, v128);
                v12 = *(_DWORD **)&v215[1];
                *(_DWORD *)(*(_QWORD *)&v215[1] + 4i64) = (_DWORD)v137 - v215[1];
                v144 = (UINT8 *)v137 + v128;
                if( v227 )
                {
                  memmove(v144, v227, v129);
                  v12[2] = (_DWORD)v144 - (_DWORD)v12;
                }
                ServerAcl = 0;
                goto LABEL_186;
              }
              v211 = v244;
LABEL_146:
              v121 |= 4u;
              v215[0] = v121;
              goto LABEL_147;
            }
            if( (v119 & 4) != 0 )
            {
              if( v119 >= 0 )
              {
                v186 = *(unsigned __int16 **)(v112 + 32);
              }
              else
              {
                v185 = *(unsigned int *)(v112 + 16);
                if( !(_DWORD)v185 )
                {
                  v211 = 0i64;
                  goto LABEL_354;
                }
                v186 = (unsigned __int16 *)(v112 + v185);
              }
              v211 = v186;
            }
            else
            {
              v211 = 0i64;
            }
LABEL_354:
            ServerAclAllocated[2] = 1;
            v121 = v120 | v119 & 0x1000;
            goto LABEL_146;
          }
          v94 = 200;
          v95 = 0;
          LODWORD(v233) = 200;
          while( 1 )
          {
            v96 = (struct _ACL *)ExAllocatePoolWithTag(PagedPool, v94, 0x63416553ui64);
            v97 = v96;
            if( !v96 )
              break;
            ServerAcl = RtlpInheritAcl2(
                          v93,
                          (unsigned __int8 *)v92,
                          v78,
                          IsDirectoryObject,
                          1,
                          0,
                          (__int64)Owner,
                          (__int64)v80,
                          (__int64)ServerSid,
                          v237,
                          v228,
                          3,
                          (__int64)pObjectTypea,
                          GuidCount,
                          (__int64)&v233,
                          v96,
                          (__int64)pIndex + 1,
                          (__int64)v220);
            if( ServerAcl >= 0 )
            {
              if( !(_DWORD)v233 )
              {
                ExFreePoolWithTag(v97, 0);
                v97 = 0i64;
              }
LABEL_110:
              if( ServerAcl == -2147483637 )
                goto LABEL_206;
              if( ServerAcl >= 0 )
              {
                v98 = v220[0];
                v99 = p_Acl;
                goto LABEL_113;
              }
              goto LABEL_482;
            }
            ExFreePoolWithTag(v97, 0);
            v97 = 0i64;
            if( ServerAcl != -1073741789 )
              goto LABEL_110;
            if( (unsigned int)++v95 >= 2 )
              goto LABEL_110;
            v94 = v233;
            v92 = p_Acl;
          }
LABEL_496:
          v139 = (unsigned __int16 *)Src;
LABEL_498:
          ServerAcl = -1073741801;
          goto LABEL_499;
        }
        v168 = *((unsigned int *)ParentDescriptora + 3);
        if( (_DWORD)v168 )
        {
          v93 = (unsigned __int8 *)ParentDescriptora + v168;
          goto LABEL_104;
        }
      }
    }
    v93 = 0i64;
    goto LABEL_104;
  }
  memset((INT64)result, 0i64);
  Acl = (struct _ACL)8388610i64;
  LODWORD(LabelSid) = v88;
  ServerAcl = RtlAddMandatoryAce(&Acl, v91, v90, *(VOID **)MandatoryFlags, AceType, (UINT64)LabelSid);
  if( ServerAcl >= 0 )
  {
    v92 = &Acl;
    goto LABEL_101;
  }
LABEL_482:
  v12 = *(_DWORD **)&v215[1];
  v141 = v211;
  v139 = (unsigned __int16 *)Src;
  v142 = v208;
LABEL_186:
  if( SecurityDescriptor )
    ExFreePoolWithTag(SecurityDescriptor, 0);
  if( ServerAclAllocated[7] && v245 )
    ExFreePoolWithTag(v245, 0);
  if( P )
    ExFreePoolWithTag(P, 0);
  if( (v217 || v214) && v139 )
    ExFreePoolWithTag(v139, 0);
  if( v218 && *(_QWORD *)&v220[1] )
    ExFreePoolWithTag(*(PVOID *)&v220[1], 0);
  if( v246 && v219 )
    ExFreePoolWithTag(v246, 0);
  if( v142 )
  {
    if( v141 )
      ExFreePoolWithTag(v141, 0);
  }
  *v253 = v12;
  return(unsigned int)ServerAcl;
}

Referenced by:

RtlpNewSecurityObject
SeAssignSecurity
SeAssignSecurityEx2