public static ControlFrame findDuplicatedGoal(ControlFrame frame, Object [] MV_returnarray) {
    { ControlFrame trialframe = frame;
      Proposition trialgoal = null;
      ControlFrame firstrealcontrolframe = ((QueryIterator)(Logic.$QUERYITERATOR$.get())).baseControlFrame.down;

      while (!(trialframe == firstrealcontrolframe)) {
        trialgoal = trialframe.proposition;
        if (trialgoal != null) {
          { Keyword testValue000 = trialgoal.kind;

            if ((testValue000 == Logic.KWD_ISA) ||
                ((testValue000 == Logic.KWD_PREDICATE) ||
                 (testValue000 == Logic.KWD_FUNCTION))) {
              { ControlFrame goalframe = null;
                ControlFrame restartframe = null;
                int restartdepth = Stella.NULL_INTEGER;

                { Object [] caller_MV_returnarray = new Object[2];

                  goalframe = ControlFrame.helpFindDuplicatedGoal(trialframe, caller_MV_returnarray);
                  restartframe = ((ControlFrame)(caller_MV_returnarray[0]));
                  restartdepth = ((int)(((IntegerWrapper)(caller_MV_returnarray[1])).wrapperValue));
                }
                if (goalframe != null) {
                  Logic.traceGoalCache("DUPLICATED GOAL: ", trialframe);
                  if ((Stella.$TRACED_KEYWORDS$ != null) &&
                      Stella.$TRACED_KEYWORDS$.membP(Logic.KWD_GOAL_CACHES)) {
                    System.out.println("   RESTART DEPTH " + restartdepth);
                  }
                  { ControlFrame _return_temp = goalframe;

                    MV_returnarray[0] = restartframe;
                    MV_returnarray[1] = IntegerWrapper.wrapInteger(restartdepth);
                    return (_return_temp);
                  }
                }
              }
            }
            else {
            }
          }
        }
        trialframe = trialframe.up;
      }
      if ((Stella.$TRACED_KEYWORDS$ != null) &&
          Stella.$TRACED_KEYWORDS$.membP(Logic.KWD_GOAL_CACHES)) {
        System.out.println("FAILED TO FIND DUPLICATE GOAL");
      }
      ((QueryIterator)(Logic.$QUERYITERATOR$.get())).failedToFindDuplicateSubgoalP = true;
      { ControlFrame _return_temp = null;

        MV_returnarray[0] = null;
        MV_returnarray[1] = IntegerWrapper.wrapInteger(Stella.NULL_INTEGER);
        return (_return_temp);
      }
    }
  }