HalpDmaAllocateContiguousPagesFromContiguousPoolV3

__int64 __fastcall HalpDmaAllocateContiguousPagesFromContiguousPoolV3(
        __int64 a1,
        __int64 a2,
        ULONG a3,
        char a4,
        char a5,
        ULONG *a6){
  __int64 v9; 
  unsigned int v10; 
  unsigned int v11; 
  __int64 result; 
  ULONG v13; 
  unsigned int ClearBitsAndSet; 
  __int64 v15; 
  __int64 v16; 
  __int64 v17; 
  struct _KLOCK_QUEUE_HANDLE LockHandle; 
  memset(&LockHandle, 0, sizeof(LockHandle));
  v9 = 0i64;
  KeAcquireInStackQueuedSpinLock((UINT64 *)(a2 + 120), &LockHandle);
  if( a5 )
  {
    v10 = *(_DWORD *)(a2 + 200);
    v9 = a2;
    v11 = *(_DWORD *)(a2 + 204);
    if( v10 <= v11 )
    {
      KeReleaseInStackQueuedSpinLockFromDpcLevel(&LockHandle);
      __writecr8(LockHandle.OldIrql);
LABEL_4:
      *a6 = 0;
      return 0i64;
    }
    v13 = v10 - v11;
    if( a3 > v13 )
      a3 = v13;
  }
  ClearBitsAndSet = -1;
  if( a3 )
  {
    while( 1 )
    {
      ClearBitsAndSet = RtlFindClearBitsAndSet(*(PRTL_BITMAP *)(a2 + 16), a3, 0);
      if( ClearBitsAndSet != -1 )
        break;
      if( !a4 )
      {
        a3 >>= 1;
        if( a3 )
          continue;
      }
      goto LABEL_14;
    }
    if( a5 )
      *(_DWORD *)(v9 + 200) -= a3;
  }
LABEL_14:
  KeReleaseInStackQueuedSpinLockFromDpcLevel(&LockHandle);
  __writecr8(LockHandle.OldIrql);
  if( ClearBitsAndSet == -1 )
    goto LABEL_4;
  result = HalpDmaLinkContiguousTranslations(a2, ClearBitsAndSet, a3);
  v15 = 0i64;
  v16 = result;
  if( a3 )
  {
    v17 = a3;
    do
    {
      v15 = v16;
      v16 = *(_QWORD *)(v16 + 8);
      --v17;
    }
    while( v17 );
  }
  *(_QWORD *)(v15 + 8) = 0i64;
  *a6 = a3;
  return result;
}

Referenced by:

HalpDmaAllocateContiguousPagesFromContiguousPool