public static AtomicGoalCache findCachedGoal(ControlFrame frame, Keyword successorfailure) {
    if (frame.state == Logic.KWD_ATOMIC_GOAL) {
      { Keyword testValue000 = frame.proposition.kind;

        if ((testValue000 == Logic.KWD_ISA) ||
            ((testValue000 == Logic.KWD_PREDICATE) ||
             (testValue000 == Logic.KWD_FUNCTION))) {
          { AtomicGoalCache cachedgoal = null;

            if (successorfailure == Logic.KWD_SUCCESS) {
              if (!Logic.$CACHE_SUCCEEDED_GOALSp$) {
                return (null);
              }
              cachedgoal = ((AtomicGoalCache)((Logic.$SUCCEEDED_GOALS_CACHE$.theArray)[((((ControlFrame.goalHashCode(frame)) & 0x7FFFFFFF) % 1541))]));
              if ((cachedgoal != null) &&
                  (AtomicGoalCache.cacheMatchesGoalP(cachedgoal, frame, true, Logic.KWD_GOAL_INSTANTIATES_CACHE) &&
                   ((!((Boolean)(Logic.$RECORD_JUSTIFICATIONSp$.get())).booleanValue()) ||
                    (cachedgoal.justification != null)))) {
                return (cachedgoal);
              }
            }
            else if (successorfailure == Logic.KWD_FAILURE) {
              if ((!Logic.$CACHE_FAILED_GOALSp$) ||
                  frame.dontCacheGoalFailureP) {
                return (null);
              }
              cachedgoal = ((AtomicGoalCache)((Logic.$FAILED_GOALS_CACHE$.theArray)[((((ControlFrame.goalHashCode(frame)) & 0x7FFFFFFF) % 1541))]));
              if ((cachedgoal != null) &&
                  AtomicGoalCache.cacheMatchesGoalP(cachedgoal, frame, false, Logic.KWD_GOAL_INSTANTIATES_CACHE)) {
                return (cachedgoal);
              }
            }
            else {
              { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

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