def merge_variables(program, node, variables):
  """Create a combined Variable for a list of variables.

  The purpose of this function is to create a final result variable for
  functions that return a list of "temporary" variables. (E.g. function
  calls).

  Args:
    program: A cfg.Program instance.
    node: The current CFG node.
    variables: A list of cfg.Variables.
  Returns:
    A cfg.Variable.
  """
  if not variables:
    return program.NewVariable()  # return empty var
  elif len(variables) == 1:
    v, = variables
    return v
  elif all(v is variables[0] for v in variables):
    return variables[0]
  else:
    v = program.NewVariable()
    for r in variables:
      v.PasteVariable(r, node)
    return v