MiInsertUnusedSegment

VOID __fastcall MiInsertUnusedSegment(_CONTROL_AREA *ControlArea){
  union {unsigned int LongFlags;_MMSECTION_FLAGS Flags;} v1; 
  __int64 v2; 
  __int64 v4; 
  __int64 v5; 
  unsigned int v6; 
  int v7; 
  _BYTE *v8; 
  _QWORD *v9; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  _QWORD *v12; 

  v1.LongFlags = (unsigned int)ControlArea->u;
  v2 = 0i64;
  if( (v1.LongFlags & 0x100) == 0 )
  {
    if( (v1.LongFlags & 0x20) == 0 )
    {
      LODWORD(v4) = MiConvertStaticSubsections(ControlArea);
      v2 = v4;
    }
    v5 = *(_QWORD *)(*(&stru_140C4DB30 + 267) + 8i64 * (ControlArea->u1.Flags._bf_0 & 0x3FF));
    ExAcquireSpinLockExclusiveAtDpcLevel((INT64 *)(v5 + 1344));
    if( !v2 )
      MiReleaseControlAreaCharges(ControlArea, 1ui64);
    v6 = ControlArea->u.LongFlags | 0x8000000;
    ControlArea->u.LongFlags = v6;
    v7 = v6;
    if( (*(_DWORD *)(v5 + 4) & 1) != 0 && (v6 & 0x40000) == 0 )
    {
      v7 = v6 | 0x40000;
      ControlArea->u.LongFlags = v6 | 0x40000;
    }
    v8 = ControlArea->gap8;
    if( (v7 & 0x40000) != 0 )
    {
      v12 = *(_QWORD **)(v5 + 1608);
      if( *v12 == v5 + 1600 )
      {
        *(_QWORD *)v8 = v5 + 1600;
        *(_QWORD *)&ControlArea->gap8[8] = v12;
        *v12 = v8;
        *(_QWORD *)(v5 + 1608) = v8;
        ++*(_DWORD *)(v5 + 1348);
        if( !*(_BYTE *)(v5 + 1680) )
        {
          *(_BYTE *)(v5 + 1680) = 1;
          KiSetTimerEx((_KTIMER *)(v5 + 1616), Mi10Milliseconds, 0i64, 0, 0i64);
        }
        goto LABEL_10;
      }
    }
    else
    {
      v9 = *(_QWORD **)(v5 + 1712);
      if( *v9 == v5 + 1704 )
      {
        *(_QWORD *)v8 = v5 + 1704;
        *(_QWORD *)&ControlArea->gap8[8] = v9;
        *v9 = v8;
        *(_QWORD *)(v5 + 1712) = v8;
LABEL_10:
        LODWORD(v10) = MiComputePagedPoolSegmentBytes((INT64)ControlArea);
        *(_QWORD *)(v5 + 1696) += v10;
        v11 = v10;
        ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)(v5 + 1344));
        _InterlockedExchangeAdd64(&qword_140C4C6D8, v11);
        return;
      }
    }
    __fastfail(3u);
  }
}

Referenced by:

MiCheckControlArea
MiCleanSection
MiDeleteCachedSegment
MiDeleteCachedSubsection
MiFlushControlArea
MiMakeUnusedSegmentDeleteOnClose
MiProcessDeleteOnClose
MiSetDeleteOnClose