public static ControlFrame handleDepthViolation(ControlFrame frame, int depth, Object [] MV_returnarray) {
    if ((Stella.$TRACED_KEYWORDS$ != null) &&
        (Stella.$TRACED_KEYWORDS$.membP(Logic.KWD_GOAL_TREE) ||
         Stella.$TRACED_KEYWORDS$.membP(Logic.KWD_GOAL_CACHES))) {
      System.out.println("*** Inference depth cutoff: depth=" + depth);
    }
    ((QueryIterator)(Logic.$QUERYITERATOR$.get())).triggeredDepthCutoffP = true;
    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, ((QueryIterator)(Logic.$QUERYITERATOR$.get())).baseControlFrame);
    }
    ControlFrame.registerInferenceCutoff(frame, Logic.KWD_DEPTH_VIOLATION);
    ((QueryIterator)(Logic.$QUERYITERATOR$.get())).depthCutoffsP = true;
    if ((Logic.$DUPLICATE_SUBGOAL_STRATEGY$ == Logic.KWD_DUPLICATE_GOALS) ||
        (Logic.$DUPLICATE_SUBGOAL_STRATEGY$ == Logic.KWD_DUPLICATE_GOALS_WITH_CACHING)) {
      ControlFrame.setFrameTruthValue(frame, Logic.UNKNOWN_TRUTH_VALUE);
      if (((((QueryIterator)(Logic.$QUERYITERATOR$.get())) != null) &&
          (((QueryIterator)(Logic.$QUERYITERATOR$.get())).partialMatchStrategy != null)) &&
          (frame.partialMatchFrame == null)) {
        ControlFrame.createAndLinkPartialMatchFrame(frame, null);
        frame.partialMatchFrame.setFramePartialTruth(null, 0.0, Stella.NULL_FLOAT, true);
      }
      if (((Boolean)(Logic.$RECORD_JUSTIFICATIONSp$.get())).booleanValue()) {
        { PrimitiveStrategy self000 = PrimitiveStrategy.newPrimitiveStrategy();

          self000.inferenceRule = Logic.KWD_DEPTH_CUTOFF;
          self000.strategy = Logic.KWD_FAILURE;
          ControlFrame.recordGoalJustification(frame, self000);
        }
      }
      frame.state = Logic.KWD_POPPED;
      frame.up.result = frame;
      frame = frame.up;
      depth = depth - 1;
    }
    else {
      { ControlFrame goalframe = null;
        ControlFrame restartframe = null;
        int restartdepth = Stella.NULL_INTEGER;

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

          goalframe = ControlFrame.findDuplicatedGoal(frame, caller_MV_returnarray);
          restartframe = ((ControlFrame)(caller_MV_returnarray[0]));
          restartdepth = ((int)(((IntegerWrapper)(caller_MV_returnarray[1])).wrapperValue));
        }
        if ((goalframe != null) &&
            ((ControlFrame.findGoalCache(goalframe) == null) &&
             ControlFrame.createGoalCacheP(goalframe))) {
          if ((Stella.$TRACED_KEYWORDS$ != null) &&
              Stella.$TRACED_KEYWORDS$.membP(Logic.KWD_GOAL_CACHES)) {
            System.out.println("*** Inference restart: restartDepth=" + restartdepth);
          }
          if (restartframe.down != null) {
            ControlFrame.popFramesUpTo(restartframe.down);
            restartframe.down = null;
          }
          frame = restartframe;
          depth = restartdepth;
        }
      }
    }
    { ControlFrame _return_temp = frame;

      MV_returnarray[0] = IntegerWrapper.wrapInteger(depth);
      return (_return_temp);
    }
  }