MiInsertUnusedSegment

UINT64 __stdcall MiInsertUnusedSegment(_CONTROL_AREA *ControlArea){
  int v1; 
  __int64 v2; 
  __int64 v4; 
  __int64 v5; 
  int v6; 
  int v7; 
  _QWORD *v8; 
  _QWORD *v9; 
  INT64 v10; 
  unsigned __int64 v11; 
  _QWORD *v13; 
  v1 = *((_DWORD *)ControlArea + 14);
  v2 = 0i64;
  if( (v1 & 0x100) == 0 )
  {
    if( (v1 & 0x20) == 0 )
      v2 = MiConvertStaticSubsections((__int64)ControlArea);
    v4 = *(_QWORD *)(qword_140C4E388 + 8i64 * (*((_WORD *)ControlArea + 30) & 0x3FF));
    ExAcquireSpinLockExclusiveAtDpcLevel((INT64 *)(v4 + 1344));
    if( !v2 )
    {
      MiReleaseControlAreaCharges(ControlArea, 1ui64);
      v2 = v5;
    }
    v6 = *((_DWORD *)ControlArea + 14) | 0x8000000;
    *((_DWORD *)ControlArea + 14) = v6;
    v7 = v6;
    if( (*(_DWORD *)(v4 + 4) & 1) != 0 && (v6 & 0x40000) == 0 )
    {
      v7 = v6 | 0x40000;
      *((_DWORD *)ControlArea + 14) = v6 | 0x40000;
    }
    v8 = (_QWORD *)((char *)ControlArea + 8);
    if( (v7 & 0x40000) != 0 )
    {
      v13 = *(_QWORD **)(v4 + 1608);
      if( *v13 == v4 + 1600 )
      {
        *v8 = v4 + 1600;
        *((_QWORD *)ControlArea + 2) = v13;
        *v13 = v8;
        *(_QWORD *)(v4 + 1608) = v8;
        ++*(_DWORD *)(v4 + 1348);
        if( !*(_BYTE *)(v4 + 1680) )
        {
          *(_BYTE *)(v4 + 1680) = 1;
          KiSetTimerEx((_KTIMER *)(v4 + 1616), Mi10Milliseconds, 0i64, 0, 0i64);
        }
        goto LABEL_10;
      }
    }
    else
    {
      v9 = *(_QWORD **)(v4 + 1712);
      if( *v9 == v4 + 1704 )
      {
        *v8 = v4 + 1704;
        *((_QWORD *)ControlArea + 2) = v9;
        *v9 = v8;
        *(_QWORD *)(v4 + 1712) = v8;
LABEL_10:
        v10 = MiComputePagedPoolSegmentBytes((INT64)ControlArea);
        *(_QWORD *)(v4 + 1696) += v10;
        v11 = v10;
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v4 + 1344));
        _InterlockedExchangeAdd64(&qword_140C4C6D8, v11);
        return v2;
      }
    }
    __fastfail(3u);
  }
  return 0i64;
}

Referenced by:

MiCheckControlArea
MiCleanSection
MiDeleteCachedSegment
MiDeleteCachedSubsection
MiFlushControlArea
MiMakeUnusedSegmentDeleteOnClose
MiProcessDeleteOnClose
MiSetDeleteOnClose