public static Stella_Object innermostOf(Stella_Object self) {
    if (Logic.descriptionModeP()) {
      { Stella_Object nextvalue = self;
        PatternVariable tightestvariable = null;
        Stella_Object equivalent = null;

        for (;;) {
          { Surrogate testValue000 = Stella_Object.safePrimaryType(nextvalue);

            if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_PATTERN_VARIABLE)) {
              { PatternVariable nextvalue000 = ((PatternVariable)(nextvalue));

                equivalent = ((Stella_Object)(Stella_Object.accessInContext(nextvalue000.variableValue, nextvalue000.homeContext, false)));
                if (equivalent == null) {
                  return (nextvalue000);
                }
                tightestvariable = nextvalue000;
              }
            }
            else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_DESCRIPTION)) {
              { Description nextvalue000 = ((Description)(nextvalue));

                return (nextvalue000);
              }
            }
            else if (Surrogate.subtypeOfP(testValue000, Logic.SGT_LOGIC_LOGIC_OBJECT)) {
              { LogicObject nextvalue000 = ((LogicObject)(nextvalue));

                return (tightestvariable);
              }
            }
            else if (Surrogate.subtypeOfSurrogateP(testValue000)) {
              { Surrogate nextvalue000 = ((Surrogate)(nextvalue));

                return (nextvalue000);
              }
            }
            else {
              return (nextvalue);
            }
          }
          nextvalue = equivalent;
        }
      }
    }
    else {
      { Stella_Object tightestvalue = self;
        Stella_Object equivalent = null;

        for (;;) {
          { Surrogate testValue001 = Stella_Object.safePrimaryType(tightestvalue);

            if (Surrogate.subtypeOfP(testValue001, Logic.SGT_LOGIC_SKOLEM)) {
              { Skolem tightestvalue000 = ((Skolem)(tightestvalue));

                if (((Stella_Object)(Stella_Object.accessInContext(tightestvalue000.variableValue, tightestvalue000.homeContext, false))) == null) {
                  return (tightestvalue000);
                }
                equivalent = ((Stella_Object)(Stella_Object.accessInContext(tightestvalue000.variableValue, tightestvalue000.homeContext, false)));
              }
            }
            else if (Surrogate.subtypeOfSurrogateP(testValue001)) {
              { Surrogate tightestvalue000 = ((Surrogate)(tightestvalue));

                if (tightestvalue000.surrogateValue == null) {
                  return (tightestvalue000);
                }
                equivalent = tightestvalue000.surrogateValue;
              }
            }
            else {
              return (tightestvalue);
            }
          }
          tightestvalue = equivalent;
        }
      }
    }
  }