RtlpCSparseBitmapPageCommit

INT64 __fastcall RtlpCSparseBitmapPageCommit(INT64 a1, UINT64 a2, INT64 *a3, _OWORD *a4){
  unsigned __int64 v5; 
  unsigned __int64 v7; 
  int v9; 
  int v11; 
  INT64 v12; 
  UINT64 v13; 
  INT64 v14; 
  INT64 v15; 
  INT64 v16; 
  INT64 v17; 
  INT64 v18[2]; 
  UINT8 v19[16]; 
  _QWORD a1a[2]; 
  INT64 v21; 
  unsigned __int64 a2a; 
  a2a = a2;
  v5 = a2 >> 15;
  v7 = a2;
  if( !_bittest64((const signed __int64 *)(a1 + 56), a2 >> 15) )
  {
    LODWORD(v17) = 0;
    v21 = 4096i64;
    v18[0] = *(_QWORD *)a1 + (v5 << 12);
    LODWORD(v15) = *(unsigned __int8 *)(a1 + 50);
    LODWORD(v14) = *(unsigned __int8 *)(a1 + 49);
    LODWORD(v13) = 4;
    v9 = RtlpHpEnvAllocVA(v18, &v21, 0i64, 1073745920i64, v13, v14, v15, v16, v17);
    if( v9 < 0 )
      return(unsigned int)v9;
    _interlockedbittestandset64((volatile signed __int32 *)(a1 + 56), v5);
    v7 = a2a;
  }
  *a4 = *(_OWORD *)RtlCSparseBitmapEnterLockingRegion(a1a, a1);
  while( 1 )
  {
    RtlpCSparseBitmapLock(a1, 0i64, (INT64)a3);
    if( *(_QWORD *)(a1 + 32) != v7 )
      break;
    RtlpCSparseBitmapUnlock(a3);
    RtlpCSparseBitmapWaitOnAddress((_QWORD *)(a1 + 32), &a2a, v12, a1);
  }
  if( !_bittest64(*(const signed __int64 **)a1, v7) )
  {
    v11 = *(unsigned __int8 *)(a1 + 49);
    LODWORD(v17) = 0;
    v18[0] = *(_QWORD *)(a1 + 8) + (v7 << 12);
    LODWORD(v15) = *(unsigned __int8 *)(a1 + 50);
    LODWORD(v14) = v11;
    v21 = 4096i64;
    LODWORD(v13) = 4;
    v9 = RtlpHpEnvAllocVA(v18, &v21, 0i64, 1073745920i64, v13, v14, v15, v16, v17);
    if( v9 < 0 )
    {
      RtlpCSparseBitmapUnlock(a3);
      *(_OWORD *)v19 = *a4;
      RtlCSparseBitmapLeaveLockingRegion(v19);
      return(unsigned int)v9;
    }
    _interlockedbittestandset64(*(volatile signed __int32 **)a1, v7);
  }
  return 0;
}

Referenced by:

RtlCSparseBitmapBitmaskWrite
RtlSparseArrayElementAllocate