Allocate fewer terms when replacing variables

Memory profiles consistently showed ReplaceVariables as a major
culprit for generating GC pressure.  In many cases, a compound term
has no variables so we can reuse the compound term we already have.
Even if there are variables, we can intelligently preserve unification
hashes when a variable is replaced with another variable.

This makes the following changes to benchmark timing:

    Append          -1.3%
    Maplist         -1.3%
    NaiveReverse    -7.3%
Make profile.sh more flexible

I can now use it to generate either CPU or memory profiles.  I can
also specify which benchmarks should be included in the profile.