private JimpleExpr getNumElementsExpr(FunctionContext context, ImExpr sizeArg, ImPrimitiveType type) {
// malloc is given a size in bytes, we need to divide by the underlying storage
// size to get the number of elements to allocate
// get the argument as a primitive expression that evaluates to number of bytes
JimpleExpr byteSizeExpr = sizeArg.translateToPrimitive(context, ImPrimitiveType.INT);
// calculate number of elements
JimpleExpr elementCount = new JimpleExpr(context.declareTemp(JimpleType.INT));
context.getBuilder().addAssignment(elementCount, JimpleExpr.binaryInfix("/", byteSizeExpr,
JimpleExpr.integerConstant(type.getStorageSizeInBytes())));
return elementCount;
}