SmHpBufferAlloc

VOID **__fastcall SmHpBufferAlloc(_DWORD *a1){
  VOID **PoolWithTag; 
  __int64 v3; 
  unsigned int v4; 
  VOID **v5; 
  _WORD *v6; 
  __int64 v7; 
  _WORD *v8; 
  unsigned __int64 i; 
  __int64 v11; 

  PoolWithTag = ExAllocatePoolWithTag(0x200ui64, 0x1000ui64, 1111715187i64);
  if( !PoolWithTag )
    return 0i64;
  v3 = (unsigned int)a1[136];
  if( (_DWORD)v3 == -1 )
  {
    v4 = a1[64];
    if( v4 > a1[65] )
    {
      v5 = 0i64;
      goto LABEL_10;
    }
    v5 = SmBinaryArrayGrow((__int64)a1, v4);
    if( !v5 )
      goto LABEL_10;
    LODWORD(v3) = a1[64];
    a1[64] = v3 + 1;
  }
  else
  {
    _BitScanReverse((unsigned int *)&v11, v3);
    v5 = (VOID **)(*(_QWORD *)&a1[2 * v11] + 16 * (v3 ^ (unsigned int)(1 << v11)));
    a1[136] = *((_DWORD *)v5 + 2);
  }
  v6 = v5 + 1;
  *(_OWORD *)PoolWithTag = 0i64;
  PoolWithTag[2] = 0i64;
  v7 = 0i64;
  *((_DWORD *)PoolWithTag + 4) = v3;
  PoolWithTag[1] = PoolWithTag;
  *PoolWithTag = PoolWithTag;
  v5[1] = 0i64;
  *v5 = PoolWithTag;
  v8 = (_WORD *)((char *)PoolWithTag + (unsigned int)a1[70]);
  for( i = (unsigned __int64)v8 + (unsigned int)a1[68];
        i <= (unsigned __int64)(PoolWithTag + 512);
        i += (unsigned int)a1[68] )
  {
    LOWORD(v7) = v7 + 1;
    *v6 = (_WORD)v8 - (_WORD)PoolWithTag;
    v6 = v8;
    v8 = (_WORD *)i;
  }
  *v6 = -1;
  SmHpBufferUpdateFullness(a1, v5, v7);
  PoolWithTag = 0i64;
LABEL_10:
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0);
  return v5;
}

Referenced by:

SmHpChunkAlloc