MiInsertSubsectionNode

VOID __stdcall MiInsertSubsectionNode(_CONTROL_AREA *ControlArea, _MSUBSECTION *Subsection, UINT64 LockHeld){
  _RTL_BALANCED_NODE **v3; 
  unsigned __int8 v6; 
  _RTL_BALANCED_NODE *v7; 
  BOOL v8; 
  unsigned __int64 v9; 
  unsigned __int64 v10; 
  unsigned __int64 v11; 
  _RTL_BALANCED_NODE *v12; 

  v3 = (_RTL_BALANCED_NODE **)&ControlArea[2].gap8[8];
  if( (_DWORD)LockHeld )
    v6 = 17;
  else
    v6 = ExAcquireSpinLockExclusive((INT64 *)&ControlArea->ControlAreaLock);
  v7 = *v3;
  v8 = 0;
  if( !*v3 )
    goto LABEL_14;
  v9 = Subsection->Core.StartingSector | ((unsigned __int64)(Subsection->Core.u.SubsectionFlags._bf_0 & 0xFFC0) << 26);
  while( 1 )
  {
    v10 = HIDWORD(v7[-1].Left) | ((unsigned __int64)((__int64)v7[-1].Children[0] & 0xFFC0) << 26);
    v11 = v10 + LODWORD(v7[-1].Right);
    if( WORD1(v7[-1].Left) < 0x10u )
      --v11;
    if( v9 <= v11 && v9 < v10 )
      break;
    v12 = v7->Children[1];
    if( !v12 )
    {
      v8 = 1;
      goto LABEL_14;
    }
LABEL_12:
    v7 = v12;
  }
  v12 = v7->Children[0];
  if( v7->Children[0] )
    goto LABEL_12;
  v8 = 0;
LABEL_14:
  RtlAvlInsertNodeEx(v3, (UINT64)v7, v8, &Subsection->SubsectionNode);
  v3[1] = (_RTL_BALANCED_NODE *)((char *)v3[1] + 1);
  v3[2] = (_RTL_BALANCED_NODE *)Subsection;
  if( v6 != 17 )
  {
    ExReleaseSpinLockExclusiveFromDpcLevel((INT64 *)&ControlArea->ControlAreaLock);
    __writecr8(v6);
  }
}

Referenced by:

MiAppendSubsectionChain
MiCreateDataFileMap