Deduped some code in val.cc into upsert_replacement_func.
Replaced dummy_var_t::{A,B,C} with term-specific names.