MiReturnCrossPartitionCombineCharges

VOID __fastcall MiReturnCrossPartitionCombineCharges(_MI_CROSS_PARTITION_CHARGES *ChargeInfo, INT64 a2){
  unsigned __int64 v3; 
  struct _KPRCB *CurrentPrcb; 
  __int64 CachedResidentAvailable; 
  bool v6; 
  signed __int32 v7; 

  if( !(_DWORD)a2 )
    goto LABEL_14;
  MiReturnCommit((_MI_PARTITION *)ChargeInfo, 1ui64);
  v3 = 1i64;
  if( ChargeInfo != (_MI_CROSS_PARTITION_CHARGES *)&Irp )
    goto LABEL_13;
  CurrentPrcb = KeGetCurrentPrcb();
  CachedResidentAvailable = (int)CurrentPrcb->CachedResidentAvailable;
  if( (_DWORD)CachedResidentAvailable == -1 )
    goto LABEL_13;
  if( (unsigned __int64)(CachedResidentAvailable + 1) > 0x100 )
  {
LABEL_8:
    if( (int)CachedResidentAvailable > 192
      && (_DWORD)CachedResidentAvailable != -1
      && (_DWORD)CachedResidentAvailable == _InterlockedCompareExchange(
                                              (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
                                              192,
                                              CachedResidentAvailable) )
    {
      v3 = (int)CachedResidentAvailable - 192 + 1i64;
    }
    if( !v3 )
      goto LABEL_14;
LABEL_13:
    _InterlockedExchangeAdd64((volatile signed __int64 *)&ChargeInfo[224], v3);
    goto LABEL_14;
  }
  while( 1 )
  {
    v7 = _InterlockedCompareExchange(
           (volatile signed __int32 *)&CurrentPrcb->CachedResidentAvailable,
           CachedResidentAvailable + 1,
           CachedResidentAvailable);
    v6 = (_DWORD)CachedResidentAvailable == v7;
    LODWORD(CachedResidentAvailable) = v7;
    if( v6 )
      break;
    if( v7 == -1 || (unsigned __int64)(v7 + 1i64) > 0x100 )
      goto LABEL_8;
  }
LABEL_14:
  MiReturnCrossPartitionCharges(ChargeInfo, 2ui64);
}

Referenced by:

MiConvertPrivateToProto
MiConvertStandbyToProto
MiDecrementCombinedPte
MiIncrementCombinedPte