diff --git a/ExprNode.cc b/ExprNode.cc
index b72f4e0e512e7f694334cd6c26fcbd61bba53405..3897415d3609a8ed5525f0564cbffb3ed0555be3 100644
--- a/ExprNode.cc
+++ b/ExprNode.cc
@@ -596,7 +596,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
           output << ")";
         }
       else
-        output << datatree.symbol_table.getName(symb_id);
+        /* We append underscores to avoid name clashes with "g1" or "oo_" (see
+           also ModelTree::writeModelLocalVariables) */
+        output << datatree.symbol_table.getName(symb_id) << "__";
       break;
 
     case eModFileLocalVariable:
diff --git a/ModelTree.cc b/ModelTree.cc
index 495860453bc9ff0ae1cc837d20acc704a3979164..b6e5fb1531051717bed38e85f43aa1d18a741835 100644
--- a/ModelTree.cc
+++ b/ModelTree.cc
@@ -1171,7 +1171,9 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t
       if (IS_C(output_type))
         output << "double ";
 
-      output << symbol_table.getName(id) << " = ";
+      /* We append underscores to avoid name clashes with "g1" or "oo_" (see
+         also VariableNode::writeOutput) */
+      output << symbol_table.getName(id) << "__ = ";
       // Use an empty set for the temporary terms
       value->writeOutput(output, output_type);
       output << ";" << endl;