public static Symbol getInstanceName(Stella_Object instanceref) {
    { Stella_Object instance = Logic.getInstance(instanceref);

      { Surrogate testValue000 = Stella_Object.safePrimaryType(instance);

        if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_LOGIC_OBJECT)) {
          { LogicObject instance000 = ((LogicObject)(instance));

            if ((instance000 != null) &&
                (instance000.surrogateValueInverse != null)) {
              return (Symbol.internSymbolInModule(instance000.surrogateValueInverse.symbolName, ((Module)(instance000.surrogateValueInverse.homeContext)), true));
            }
          }
        }
        else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_STELLA_THING)) {
          { Thing instance000 = ((Thing)(instance));

            if ((instance000 != null) &&
                (instance000.surrogateValueInverse != null)) {
              return (Symbol.internSymbolInModule(instance000.surrogateValueInverse.symbolName, ((Module)(instance000.surrogateValueInverse.homeContext)), true));
            }
          }
        }
        else {
          { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

            stream000.nativeStream.print("`" + testValue000 + "' is not a valid case option");
            throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
          }
        }
      }
      return (null);
    }
  }