public static boolean checkForDuplicateGoalP(ControlFrame frame) {
    if (!((Logic.$DUPLICATE_SUBGOAL_STRATEGY$ == Logic.KWD_DUPLICATE_GOALS) ||
        (Logic.$DUPLICATE_SUBGOAL_STRATEGY$ == Logic.KWD_DUPLICATE_GOALS_WITH_CACHING))) {
      return (false);
    }
    { GeneralizedSymbol operator = frame.proposition.operator;
      Cons goalbindings = frame.goalBindings;
      ControlFrame previousframe = frame.up;
      ControlFrame duplicateframe = null;

      { int i = Stella.NULL_INTEGER;
        int iter000 = 1;
        int upperBound000 = Logic.$DUPLICATE_GOAL_SEARCH_DEPTH$;
        boolean unboundedP000 = upperBound000 == Stella.NULL_INTEGER;

        loop000 : for (;unboundedP000 ||
                  (iter000 <= upperBound000); iter000 = iter000 + 1) {
          i = iter000;
          i = i;
          if (previousframe == null) {
            break loop000;
          }
          { boolean testValue000 = false;

            testValue000 = previousframe.goalBindings != null;
            if (testValue000) {
              testValue000 = operator == previousframe.proposition.operator;
              if (testValue000) {
                { boolean alwaysP000 = true;

                  { Stella_Object b1 = null;
                    Cons iter001 = goalbindings;
                    Stella_Object b2 = null;
                    Cons iter002 = previousframe.goalBindings;

                    loop001 : for (;(!(iter001 == Stella.NIL)) &&
                              (!(iter002 == Stella.NIL)); iter001 = iter001.rest, iter002 = iter002.rest) {
                      b1 = iter001.value;
                      b2 = iter002.value;
                      if (!Stella_Object.eqlP(b1, b2)) {
                        alwaysP000 = false;
                        break loop001;
                      }
                    }
                  }
                  testValue000 = alwaysP000;
                }
                if (testValue000) {
                  testValue000 = frame.reversePolarityP == previousframe.reversePolarityP;
                }
              }
            }
            if (testValue000) {
              duplicateframe = previousframe;
              break loop000;
            }
          }
          previousframe = previousframe.up;
        }
      }
      if (duplicateframe != null) {
        Logic.traceGoalCache("DUPLICATE GOAL:", frame);
        if ((Logic.$CACHE_SUCCEEDED_GOALSp$ ||
            Logic.$CACHE_FAILED_GOALSp$) &&
            ((Logic.$DUPLICATE_SUBGOAL_STRATEGY$ == Logic.KWD_DUPLICATE_GOALS) &&
             (!((((QueryIterator)(Logic.$QUERYITERATOR$.get())) != null) &&
            (((QueryIterator)(Logic.$QUERYITERATOR$.get())).partialMatchStrategy != null))))) {
          ControlFrame.dontCacheGoalFailureBetweenFrames(frame, duplicateframe.down);
        }
        return (true);
      }
      else {
        return (false);
      }
    }
  }