public static void optimizeQuery(Description description, BooleanVector booleanvector, ControlFrame parentframe) {
    { ControlFrame frame = ControlFrame.createDownFrame(parentframe, null);
      int variablescount = description.ioVariables.length() + description.internalVariables.length() + (((((Vector)(KeyValueList.dynamicSlotValue(description.dynamicSlots, Logic.SYM_LOGIC_EXTERNAL_VARIABLES, null))) != null) ? ((Vector)(KeyValueList.dynamicSlotValue(description.dynamicSlots, Logic.SYM_LOGIC_EXTERNAL_VARIABLES, null))).length() : 0));

      Logic.initializeOptimizerMemory(variablescount);
      ControlFrame.createPatternRecord(frame, null, null);
      PatternRecord.activatePatternRecord(frame.patternRecord, variablescount);
      { PatternVariable iovar = null;
        Vector vector000 = description.ioVariables;
        int index000 = 0;
        int length000 = vector000.length();
        BooleanWrapper initiallyboundP = null;
        BooleanVector vector001 = booleanvector;
        int index001 = 0;
        int length001 = vector001.length();

        for (;(index000 < length000) &&
                  (index001 < length001); index000 = index000 + 1, index001 = index001 + 1) {
          iovar = ((PatternVariable)((vector000.theArray)[index000]));
          initiallyboundP = ((BooleanWrapper)((vector001.theArray)[index001]));
          if (BooleanWrapper.coerceWrappedBooleanToBoolean(initiallyboundP)) {
            Logic.simulateBindVariableToValue(iovar);
          }
        }
      }
      { Object old$Queryoptimizercontrolframe$000 = Logic.$QUERYOPTIMIZERCONTROLFRAME$.get();

        try {
          Native.setSpecial(Logic.$QUERYOPTIMIZERCONTROLFRAME$, frame);
          Proposition.simulateAndOptimizeQuery(description.proposition);

        } finally {
          Logic.$QUERYOPTIMIZERCONTROLFRAME$.set(old$Queryoptimizercontrolframe$000);
        }
      }
      frame.state = Logic.KWD_PATTERN;
      ControlFrame.popDownFrame(parentframe);
    }
  }