SPCallServerHandleQueryPolicy

NTSTATUS __stdcall SPCallServerHandleQueryPolicy(INT64 a1, INT64 a2, UINT64 a3, INT64 a4){
  size_t v6; 
  VOID **v7; 
  unsigned int v8; 
  unsigned int *v9; 
  unsigned int *v10; 
  unsigned int i; 
  __int64 v12; 
  unsigned int *v13; 
  NTSTATUS v14; 
  __int64 *v15; 
  UINT64 v16; 
  unsigned int j; 
  __int64 v18; 
  unsigned int *v19; 
  UINT64 v20; 
  VOID *v21; 
  NTSTATUS v22; 
  __int64 v23; 
  unsigned int v24; 
  __int64 *v25; 
  VOID **PoolWithTag; 
  VOID **v27; 
  unsigned int *v28; 
  unsigned int *v29; 
  unsigned int k; 
  unsigned int v31; 
  unsigned int v32; 
  size_t *jj; 
  __int64 v34; 
  unsigned int v35; 
  unsigned int v36; 
  unsigned int v37; 
  _DWORD *kk; 
  __int64 v40; 
  __int64 v41; 
  unsigned int v42; 
  unsigned int v43; 
  _DWORD *mm; 
  unsigned int v45; 
  int v46; 
  unsigned int v47; 
  unsigned int v48; 
  unsigned int v49; 
  int v50; 
  unsigned int v51; 
  int *v52; 
  unsigned int m; 
  unsigned int v54; 
  size_t *v55; 
  int v56; 
  int v57; 
  int v58; 
  int v59; 
  unsigned int v60; 
  unsigned int v61; 
  unsigned int v62; 
  int v63; 
  unsigned int v64; 
  _BYTE *v65; 
  int v66; 
  unsigned int v67; 
  unsigned int v68; 
  unsigned int v69; 
  volatile unsigned __int64 TickCountQuad; 
  unsigned int v71; 
  signed __int64 v72; 
  int v73; 
  __int64 v74; 
  int v75; 
  int v76; 
  double v77; 
  int v78; 
  unsigned int v79; 
  VOID **v80; 
  int v81; 
  unsigned int v82; 
  __int64 v83; 
  unsigned int v84; 
  unsigned int v85; 
  unsigned __int64 n; 
  __int64 v87; 
  __int64 v88; 
  unsigned int v89; 
  int v90; 
  unsigned int v91; 
  _DWORD *ii; 
  unsigned int v93; 
  unsigned int v94; 
  int v95; 
  unsigned int v96; 
  unsigned int v97; 
  int v98; 
  unsigned int v99; 
  int v100; 
  unsigned int v101; 
  NTSTATUS v102; 
  _BYTE *v103; 
  unsigned __int64 v104; 
  unsigned __int64 v105; 
  __int64 v106; 
  unsigned int *v107; 
  __int64 v108; 
  unsigned int *v109; 
  volatile unsigned __int64 v110; 
  unsigned int v111; 
  signed __int64 v112; 
  INT64 v113; 
  int v114; 
  NTSTATUS v115; 
  unsigned int v116; 
  unsigned int *v117; 
  unsigned int v118; 
  unsigned int v119; 
  int v120; 
  unsigned int v121; 
  PLARGE_INTEGER Timeout; 
  UINT64 MatchingChangeStamp; 
  UINT64 CheckStamp; 
  INT64 v125; 
  int v126; 
  unsigned int v127; 
  int v128; 
  unsigned int v129; 
  int v130; 
  UINT64 NumberOfBytes; 
  int v132; 
  int v133; 
  int v134; 
  int v135; 
  int v136; 
  int v137; 
  VOID *Src; 
  size_t Size[2]; 
  int v140; 
  INT64 v141; 
  PVOID P; 
  UINT64 pcbLength; 
  __int64 v144; 
  _UNICODE_STRING DestinationString; 
  _LARGE_INTEGER v146; 
  _UNICODE_STRING v147; 
  __int64 v148; 
  int v149; 

  v129 = a3;
  v141 = a2;
  NumberOfBytes = 0i64;
  v144 = 0i64;
  P = 0i64;
  v6 = 0;
  v137 = 0;
  v7 = 0i64;
  v8 = 0;
  v127 = 0;
  v146.QuadPart = 0i64;
  DestinationString = 0i64;
  if( !a1 || !a2 || !a4 )
    return -1073741811;
  v9 = *(unsigned int **)(a1 + 8);
  if( v9 )
  {
    if( *(_DWORD *)a1 <= 3u )
    {
      v14 = -1073741811;
    }
    else
    {
      v10 = *(unsigned int **)(a1 + 8);
      for( i = 0; i < 3; ++i )
      {
        v12 = *v10;
        v13 = v10 + 1;
        if( v10 + 1 < v10 )
          goto LABEL_8;
        v10 = (unsigned int *)((char *)v13 + v12);
        if( (unsigned int *)((char *)v13 + v12) < v13 )
          goto LABEL_8;
      }
      v24 = *v10;
      v25 = (__int64 *)(v10 + 1);
      if( v10 + 1 < v10 )
      {
LABEL_8:
        v14 = -1073741675;
        goto LABEL_13;
      }
      v15 = 0i64;
      if( v24 )
        v15 = v25;
      v14 = 0;
      if( v24 != 8 )
        return -1073741789;
      v144 = *v15;
    }
  }
  else
  {
    v14 = -1073741811;
  }
LABEL_13:
  if( v14 < 0 )
    return v14;
  LODWORD(v16) = 0;
  Src = 0i64;
  pcbLength = 0i64;
  if( v9 )
  {
    if( *(_DWORD *)a1 > 4u )
    {
      for( j = 0; j < 4; ++j )
      {
        v18 = *v9;
        v19 = v9 + 1;
        if( v9 + 1 < v9 )
          goto LABEL_34;
        v9 = (unsigned int *)((char *)v19 + v18);
        if( (unsigned int *)((char *)v19 + v18) < v19 )
          goto LABEL_34;
      }
      v20 = *v9;
      if( v9 + 1 < v9 )
      {
LABEL_34:
        v22 = -1073741675;
        goto LABEL_35;
      }
      v21 = 0i64;
      if( (_DWORD)v20 )
        v21 = v9 + 1;
      Src = v21;
      v22 = 0;
      if( (_DWORD)v20 )
      {
        if( (v20 & 1) != 0 )
        {
          v22 = -1073741762;
        }
        else
        {
          v23 = (unsigned int)v20;
          if( *((_WORD *)v21 + ((unsigned __int64)(unsigned int)v20 >> 1) - 1) )
          {
            v22 = -1073741762;
          }
          else if( StringCbLengthW((WCHAR *)v21, v20, &pcbLength) < 0 )
          {
            v22 = -1073741762;
          }
          else
          {
            if( pcbLength + 2 == v23 )
            {
              v16 = pcbLength >> 1;
              goto LABEL_35;
            }
            v22 = -1073741762;
          }
        }
      }
      else
      {
        v22 = -1073741762;
      }
      goto LABEL_39;
    }
    v22 = -1073741811;
  }
  else
  {
    v22 = -1073741811;
  }
LABEL_35:
  if( v22 < 0 )
    goto LABEL_61;
  if( 2 * (_DWORD)v16 == -2 )
  {
    v22 = -1073741762;
  }
  else
  {
    *(_QWORD *)Size = (unsigned int)(2 * v16 + 2);
    PoolWithTag = ExAllocatePoolWithTag(1ui64, *(UINT64 *)Size, 542329939i64);
    v27 = PoolWithTag;
    if( PoolWithTag )
    {
      v22 = 0;
      memmove(PoolWithTag, Src, Size[0]);
      P = v27;
    }
    else
    {
      v22 = -1073741801;
    }
  }
LABEL_39:
  if( v22 < 0 )
    goto LABEL_61;
  v28 = *(unsigned int **)(a1 + 8);
  if( v28 )
  {
    if( *(_DWORD *)a1 > 5u )
    {
      v29 = *(unsigned int **)(a1 + 8);
      for( k = 0; k < 5; ++k )
      {
        v106 = *v29;
        v107 = v29 + 1;
        if( v29 + 1 < v29 )
          goto LABEL_233;
        v29 = (unsigned int *)((char *)v107 + v106);
        if( (unsigned int *)((char *)v107 + v106) < v107 )
          goto LABEL_233;
      }
      v51 = *v29;
      v52 = (int *)(v29 + 1);
      if( v29 + 1 < v29 )
      {
LABEL_233:
        v22 = -1073741675;
        goto LABEL_109;
      }
      if( !v51 )
        v52 = 0i64;
      v22 = 0;
      if( v51 == 4 )
      {
        v137 = *v52;
        goto LABEL_109;
      }
      v22 = -1073741789;
      goto LABEL_61;
    }
    v22 = -1073741811;
  }
  else
  {
    v22 = -1073741811;
  }
LABEL_109:
  if( v22 < 0 )
    goto LABEL_61;
  if( v28 )
  {
    if( *(_DWORD *)a1 > 6u )
    {
      for( m = 0; m < 6; ++m )
      {
        v108 = *v28;
        v109 = v28 + 1;
        if( v28 + 1 < v28 )
          goto LABEL_241;
        v28 = (unsigned int *)((char *)v109 + v108);
        if( (unsigned int *)((char *)v109 + v108) < v109 )
          goto LABEL_241;
      }
      v54 = *v28;
      v55 = v28 + 1;
      if( v28 + 1 < v28 )
      {
LABEL_241:
        v22 = -1073741675;
        goto LABEL_118;
      }
      if( !v54 )
        v55 = 0i64;
      v22 = 0;
      if( v54 == 4 )
      {
        v6 = *v55;
        goto LABEL_118;
      }
      v22 = -1073741789;
      goto LABEL_61;
    }
    v22 = -1073741811;
  }
  else
  {
    v22 = -1073741811;
  }
LABEL_118:
  if( v22 < 0 )
    goto LABEL_61;
  RtlInitUnicodeString(&DestinationString, (PCWSTR)P);
  if( v6 )
  {
    v56 = 1;
    if( v6 <= 0x100000 )
      goto LABEL_121;
  }
  else
  {
    v56 = 0;
  }
  v100 = ((__int64(__fastcall *)(_UNICODE_STRING *, char *, _QWORD, _QWORD, unsigned int *))qword_140D2C4B8)(
           &DestinationString,
           (char *)&NumberOfBytes + 4,
           0i64,
           0i64,
           &v127);
  v58 = v100;
  if( v100 == -1073741789 )
  {
    v101 = v127;
    if( v6 < v127 )
    {
      if( !v6 )
        v58 = 0;
      goto LABEL_126;
    }
  }
  else
  {
    if( v100 < 0 )
    {
      v22 = v100;
      goto LABEL_61;
    }
    v101 = v127;
    if( v127 )
    {
      v22 = -2147418113;
      goto LABEL_61;
    }
    v56 = 0;
  }
  v6 = v101;
  v58 = 0;
  if( !v56 )
    goto LABEL_126;
LABEL_121:
  v7 = ExAllocatePoolWithTag(1ui64, v6, 542329939i64);
  if( !v7 )
  {
    v22 = -1073741801;
    goto LABEL_61;
  }
  v57 = ((__int64(__fastcall *)(_UNICODE_STRING *, char *, VOID **, _QWORD, unsigned int *))qword_140D2C4B8)(
          &DestinationString,
          (char *)&NumberOfBytes + 4,
          v7,
          v6,
          &v127);
  v58 = v57;
  if( v57 != -1073741789 )
  {
    v22 = v57;
    if( v57 < 0 )
      goto LABEL_61;
  }
  if( v6 >= v127 )
    v6 = v127;
LABEL_126:
  v59 = v6 + 4;
  LODWORD(Src) = v6 + 4;
  if( v6 >= 0xFFFFFFFC )
  {
    v22 = -1073741675;
    v59 = 8;
  }
  else
  {
    v22 = 0;
  }
  if( v22 < 0 )
  {
    v62 = 0;
  }
  else
  {
    v60 = v59 + 28;
    if( v60 < 0x1C )
      goto LABEL_60;
    v61 = v60 + 8;
    if( v60 + 8 < v60 )
      goto LABEL_60;
    v62 = v60 + 16;
    LODWORD(NumberOfBytes) = v61 + 8;
    if( v61 + 8 < v61 )
      goto LABEL_60;
    v22 = 0;
  }
  if( v22 < 0 )
    goto LABEL_61;
  v63 = 0;
  v64 = v62 + 8;
  if( v64 < 8 )
    goto LABEL_60;
  v65 = (_BYTE *)((v64 + 7) & 0xFFFFFFF8);
  if( (unsigned int)v65 >= v64 )
  {
    v63 = (_DWORD)v65 + 8;
    if( (int)v65 + 8 < (unsigned int)v65 )
      goto LABEL_139;
    v22 = 0;
  }
  else
  {
    v22 = -1073741675;
  }
  if( v22 < 0 )
  {
LABEL_140:
    v69 = 0;
    goto LABEL_141;
  }
  v66 = *(_DWORD *)(v141 + 32);
  v65 = (_BYTE *)*(unsigned int *)(v141 + 16);
  v67 = v63 + 4;
  v68 = v63 + 8;
  if( v68 < v67
    || (v93 = v68 + (_DWORD)v65, v68 + (unsigned int)v65 < v68)
    || (v65 = (_BYTE *)(v93 + 4), (unsigned int)v65 < v93)
    || (v69 = (_DWORD)v65 + v66, (int)v65 + v66 < (unsigned int)v65) )
  {
LABEL_139:
    v22 = -1073741675;
    goto LABEL_140;
  }
  v22 = 0;
LABEL_141:
  if( v22 < 0 )
    goto LABEL_61;
  if( v129 >= v69 && v58 >= 0 )
  {
    v129 = 0;
    if( DestinationString.Length == ::DestinationString.Length
      && !memcmp(DestinationString.Buffer, ::DestinationString.Buffer, ::DestinationString.Length) )
    {
      v129 = dword_140D2C130;
      v126 = 1;
    }
    else
    {
      v126 = 0;
    }
    TickCountQuad = KUSER_SHARED_DATA.TickCountQuad;
    KeQueryTimeIncrement(v65);
    v72 = TickCountQuad * v71;
    v147 = 0i64;
    v73 = 1;
    v130 = 1;
    v74 = v72 / 10000;
    v132 = 0;
    v133 = 0;
    v140 = 0;
    RtlInitUnicodeString(&v147, L"Security-SPP-GenuineLocalStatus");
    v75 = ((__int64(__fastcall *)(_UNICODE_STRING *, int *, int *, __int64, int *))qword_140D2C4B8)(
            &v147,
            &v132,
            &v133,
            4i64,
            &v140);
    if( v75 == -1073741772 || v75 >= 0 && (v132 != 4 || !v133) )
    {
      v73 = 0;
      v130 = 0;
    }
    if( g_ulOldGenuineStateForWnf != v73 )
    {
      g_qwSystemInitTime = v74;
      g_ulOldGenuineStateForWnf = v73;
    }
    v76 = v74 - g_qwSystemInitTime;
    if( v74 - g_qwSystemInitTime < 0 )
    {
      v105 = v76 & 1 | ((unsigned __int64)(v74 - g_qwSystemInitTime) >> 1);
      v77 = (double)(int)v105 + (double)(int)v105;
    }
    else
    {
      v77 = (double)v76;
    }
    if( !v73 && !g_bWNFEventFired )
    {
      if( v77 < 9000000.0 )
      {
        v78 = v126;
        if( !v126 )
          goto LABEL_156;
      }
      LODWORD(CheckStamp) = 0;
      LODWORD(MatchingChangeStamp) = 0;
      g_bWNFEventFired = 1;
      ZwUpdateWnfStateData(&WNF_OLIC_OS_LICENSE_NON_GENUINE, 0i64, 0i64, 0i64, 0i64, MatchingChangeStamp, CheckStamp);
    }
    v78 = v126;
LABEL_156:
    if( (unsigned __int64)(v74 - g_qwSystemInitTime) >= 0xA4CBFB || v78 )
    {
      v102 = KeWaitForSingleObject((UINT64)&SbiVmbusArrivalEvent + 2848, 6, 1, 0, (INT64)&v146);
      if( v102 >= 0 && v102 != 192 && v102 != 258 )
      {
        if( g_ulOldGenuineState != v73 )
        {
          if( v73 )
          {
            KeResetEvent((_KEVENT *)((char *)&SbiVmbusArrivalEvent + 2816));
          }
          else
          {
            v110 = KUSER_SHARED_DATA.TickCountQuad;
            KeQueryTimeIncrement(v103);
            v112 = v110 * v111;
            v73 = v130;
            qword_140D2C168 = v112 / 10000;
          }
        }
        v104 = v74 - qword_140D2C168;
        g_ulOldGenuineState = v73;
        if( v73 || v104 < 0xADF4FC && !v126 || !dword_140D2C1D4 )
          goto LABEL_279;
        KeSetEvent((PRKEVENT)((char *)&SbiVmbusArrivalEvent + 2816), 1, 0);
        v114 = dword_140D2C0BC;
        if( !dword_140D2C0BC )
        {
          v134 = 4;
          v128 = 0;
          LODWORD(v141) = 0;
          *(_QWORD *)Size = 0i64;
          v115 = ZwOpenKey(
                   (VOID **)Size,
                   (unsigned int)(dword_140D2C0BC + 1),
                   &stru_140D2C880,
                   v113,
                   (INT64)Timeout,
                   MatchingChangeStamp,
                   CheckStamp,
                   v125);
          if( v115 < 0 )
          {
            v115 = ((__int64(__fastcall *)(wchar_t *, int *, int *, __int64, INT64 *))qword_140D2C4B8)(
                     aBd,
                     &v134,
                     &v128,
                     4i64,
                     &v141);
            v114 = v128;
          }
          else
          {
            v114 = 3;
            v128 = 3;
          }
          if( v115 < 0 || v134 != 4 || (unsigned int)(v114 - 1) > 2 )
          {
            v114 = 1;
            v128 = 1;
          }
          if( *(_QWORD *)Size )
            ZwClose(Size[0]);
        }
        v135 = 0;
        v148 = 0i64;
        v149 = 0;
        v136 = 0;
        if( (int)((__int64(__fastcall *)(wchar_t *, int *, __int64 *, __int64, int *))qword_140D2C4B8)(
                    aLn,
                    &v135,
                    &v148,
                    12i64,
                    &v136) >= 0
          && v135 == 3
          && v136 == 12 )
        {
          v116 = 0;
          v117 = (unsigned int *)&v148;
          while( 1 )
          {
            v118 = *v117;
            if( (*v117 & 0xF) == v114 )
              break;
            ++v116;
            ++v117;
            if( v116 >= 3 )
              goto LABEL_276;
          }
        }
        else
        {
LABEL_276:
          v118 = dword_140D2C064 & 0xFFFF0000 | 0x3211;
        }
        dword_140D2C064 = v118;
        if( v137 || v129 )
          v8 = v118;
        else
LABEL_279:
          KeReleaseMutex((_KMUTANT *)((char *)&SbiVmbusArrivalEvent + 2848), 0);
      }
    }
  }
  v79 = NumberOfBytes;
  *(_DWORD *)(a4 + 4) = NumberOfBytes;
  if( !v79 )
  {
    v22 = -1073741762;
    goto LABEL_61;
  }
  v80 = ExAllocatePoolWithTag(1ui64, v79, 542329939i64);
  if( !v80 )
  {
    v22 = -1073741801;
    goto LABEL_61;
  }
  *(_QWORD *)(a4 + 8) = v80;
  *(_DWORD *)a4 = 0;
  v81 = v58 | 0x10000000;
  if( (VOID **)((char *)v80 + 4) < v80 )
    goto LABEL_60;
  if( v80 + 1 > (VOID **)((char *)v80 + *(unsigned int *)(a4 + 4)) )
  {
    v22 = -1073741789;
    goto LABEL_61;
  }
  *(_DWORD *)v80 = 4;
  *((_DWORD *)v80 + 1) = v81;
  v82 = ++*(_DWORD *)a4;
  v83 = *(_QWORD *)(a4 + 8);
  v84 = 0;
  v50 = -1;
  if( v83 )
  {
    v85 = 0;
    for( n = *(_QWORD *)(a4 + 8); v85 < v82; n += v84 )
    {
      if( *(_DWORD *)n >= 0xFFFFFFFC )
      {
        v22 = -1073741675;
      }
      else
      {
        v84 = *(_DWORD *)n + 4;
        v22 = 0;
      }
      if( v22 < 0 )
        goto LABEL_61;
      if( n + v84 < n )
        goto LABEL_60;
      ++v85;
    }
    if( n + 4 < n )
      goto LABEL_60;
    v22 = 0;
    if( n + 12 > v83 + (unsigned __int64)*(unsigned int *)(a4 + 4) )
    {
      v22 = -1073741789;
      goto LABEL_61;
    }
    v87 = v144;
    *(_DWORD *)n = 8;
    *(_QWORD *)(n + 4) = v87;
    ++*(_DWORD *)a4;
  }
  else
  {
    v94 = *(_DWORD *)(a4 + 4);
    v95 = -1;
    v96 = v94 + 12;
    if( v94 + 12 >= v94 )
      v95 = v94 + 12;
    v22 = v96 < v94 ? 0xC0000095 : 0;
    *(_DWORD *)(a4 + 4) = v95;
    if( v96 >= v94 )
    {
      *(_DWORD *)a4 = v82 + 1;
      goto LABEL_173;
    }
  }
  if( v22 < 0 )
    goto LABEL_61;
LABEL_173:
  v88 = *(_QWORD *)(a4 + 8);
  v89 = 0;
  v90 = HIDWORD(NumberOfBytes);
  if( v88 )
  {
    v91 = 0;
    for( ii = *(_DWORD **)(a4 + 8); v91 < *(_DWORD *)a4; ii = (_DWORD *)((char *)ii + v89) )
    {
      if( *ii >= 0xFFFFFFFC )
      {
        v22 = -1073741675;
      }
      else
      {
        v89 = *ii + 4;
        v22 = 0;
      }
      if( v22 < 0 )
        goto LABEL_61;
      if( (_DWORD *)((char *)ii + v89) < ii )
        goto LABEL_60;
      ++v91;
    }
    if( ii + 1 < ii )
      goto LABEL_60;
    v22 = 0;
    if( (unsigned __int64)(ii + 2) > v88 + (unsigned __int64)*(unsigned int *)(a4 + 4) )
    {
      v22 = -1073741789;
      goto LABEL_61;
    }
    *ii = 4;
    ii[1] = v90;
    ++*(_DWORD *)a4;
  }
  else
  {
    v97 = *(_DWORD *)(a4 + 4);
    v98 = -1;
    v99 = v97 + 8;
    if( v97 + 8 >= v97 )
      v98 = v97 + 8;
    v22 = v99 < v97 ? 0xC0000095 : 0;
    *(_DWORD *)(a4 + 4) = v98;
    if( v99 >= v97 )
    {
      ++*(_DWORD *)a4;
      goto LABEL_69;
    }
  }
  if( v22 < 0 )
    goto LABEL_61;
LABEL_69:
  v31 = 0;
  if( v7 )
  {
    if( v6 )
      goto LABEL_71;
LABEL_295:
    v22 = -1073741811;
    goto LABEL_53;
  }
  if( v6 )
    goto LABEL_295;
LABEL_71:
  v40 = *(_QWORD *)(a4 + 8);
  if( v40 )
  {
    v32 = 0;
    for( jj = *(size_t **)(a4 + 8); v32 < *(_DWORD *)a4; jj = (size_t *)((char *)jj + v31) )
    {
      if( *jj < 0xFFFFFFFC )
      {
        v31 = *jj + 4;
        v22 = 0;
      }
      else
      {
        v22 = -1073741675;
      }
      if( v22 < 0 )
        goto LABEL_61;
      if( (size_t *)((char *)jj + v31) < jj )
        goto LABEL_60;
      ++v32;
    }
    if( jj + 1 < jj )
      goto LABEL_60;
    v22 = 0;
    if( (unsigned __int64)jj + v6 + 4 > v40 + (unsigned __int64)*(unsigned int *)(a4 + 4) )
    {
      v22 = -1073741789;
      goto LABEL_61;
    }
    *jj = v6;
    if( v7 )
      memmove(jj + 1, v7, v6);
    ++*(_DWORD *)a4;
  }
  else
  {
    if( (unsigned int)Src < 4 )
    {
      v22 = -1073741675;
    }
    else
    {
      v31 = (unsigned int)Src;
      v22 = 0;
    }
    if( v22 < 0 )
      goto LABEL_61;
    v119 = *(_DWORD *)(a4 + 4);
    v120 = -1;
    v121 = v119 + v31;
    if( v119 + v31 >= v119 )
      v120 = v119 + v31;
    v22 = v121 < v119 ? 0xC0000095 : 0;
    *(_DWORD *)(a4 + 4) = v120;
    if( v121 >= v119 )
    {
      ++*(_DWORD *)a4;
      goto LABEL_54;
    }
  }
LABEL_53:
  if( v22 < 0 )
    goto LABEL_61;
LABEL_54:
  v34 = *(_QWORD *)(a4 + 8);
  v35 = 0;
  v36 = v127;
  if( v34 )
  {
    v37 = 0;
    for( kk = *(_DWORD **)(a4 + 8); v37 < *(_DWORD *)a4; kk = (_DWORD *)((char *)kk + v35) )
    {
      if( *kk >= 0xFFFFFFFC )
      {
        v22 = -1073741675;
      }
      else
      {
        v35 = *kk + 4;
        v22 = 0;
      }
      if( v22 < 0 )
        goto LABEL_61;
      if( (_DWORD *)((char *)kk + v35) < kk )
        goto LABEL_60;
      ++v37;
    }
    if( kk + 1 < kk )
      goto LABEL_60;
    v22 = 0;
    if( (unsigned __int64)(kk + 2) > v34 + (unsigned __int64)*(unsigned int *)(a4 + 4) )
    {
      v22 = -1073741789;
      goto LABEL_61;
    }
    *kk = 4;
    kk[1] = v36;
    ++*(_DWORD *)a4;
  }
  else
  {
    v45 = *(_DWORD *)(a4 + 4);
    v46 = -1;
    v47 = v45 + 8;
    if( v45 + 8 >= v45 )
      v46 = v45 + 8;
    v22 = v47 < v45 ? 0xC0000095 : 0;
    *(_DWORD *)(a4 + 4) = v46;
    if( v47 >= v45 )
    {
      ++*(_DWORD *)a4;
      goto LABEL_80;
    }
  }
  if( v22 < 0 )
    goto LABEL_61;
LABEL_80:
  v41 = *(_QWORD *)(a4 + 8);
  v42 = 0;
  if( !v41 )
  {
    v48 = *(_DWORD *)(a4 + 4);
    v49 = v48 + 8;
    if( v48 + 8 >= v48 )
      v50 = v48 + 8;
    v22 = v49 < v48 ? 0xC0000095 : 0;
    *(_DWORD *)(a4 + 4) = v50;
    if( v49 < v48 )
      goto LABEL_90;
    ++*(_DWORD *)a4;
    v22 = 0;
    goto LABEL_61;
  }
  v43 = 0;
  for( mm = *(_DWORD **)(a4 + 8); v43 < *(_DWORD *)a4; mm = (_DWORD *)((char *)mm + v42) )
  {
    if( *mm >= 0xFFFFFFFC )
    {
      v22 = -1073741675;
    }
    else
    {
      v42 = *mm + 4;
      v22 = 0;
    }
    if( v22 < 0 )
      goto LABEL_61;
    if( (_DWORD *)((char *)mm + v42) < mm )
      goto LABEL_60;
    ++v43;
  }
  if( mm + 1 < mm )
  {
LABEL_60:
    v22 = -1073741675;
    goto LABEL_61;
  }
  v22 = 0;
  if( (unsigned __int64)(mm + 2) <= v41 + (unsigned __int64)*(unsigned int *)(a4 + 4) )
  {
    *mm = 4;
    mm[1] = v8;
    ++*(_DWORD *)a4;
LABEL_90:
    if( v22 >= 0 )
      v22 = 0;
    goto LABEL_61;
  }
  v22 = -1073741789;
LABEL_61:
  if( P )
    ExFreePoolWithTag(P, 0x20534C53u);
  if( v7 )
    ExFreePoolWithTag(v7, 0x20534C53u);
  return v22;
}

Referenced by:

sub_1405F50F8