public static void dynamicallyReoptimizeArguments(Vector arguments, int cursor) {
    { int lastargindex = arguments.length() - 1;
      int cheapestargindex = cursor;
      double cost = Stella.NULL_FLOAT;
      double fanout = Stella.NULL_FLOAT;
      double unbound = Stella.NULL_FLOAT;
      int nofboundargs = 0;
      double bestcost = Stella.NULL_FLOAT;
      int bestnofboundargs = 0;
      Proposition argument = null;

      if (cursor >= lastargindex) {
        return;
      }
      { int i = Stella.NULL_INTEGER;
        int iter000 = cursor;
        int upperBound000 = lastargindex;
        boolean unboundedP000 = upperBound000 == Stella.NULL_INTEGER;

        loop000 : for (;unboundedP000 ||
                  (iter000 <= upperBound000); iter000 = iter000 + 1) {
          i = iter000;
          argument = ((Proposition)((arguments.theArray)[i]));
          if (Proposition.containsOperatorP(argument, Logic.SGT_PL_KERNEL_KB_CUT) ||
              Proposition.containsOperatorP(argument, Logic.SGT_PL_KERNEL_KB_BOUND_VARIABLES)) {
            break loop000;
          }
          unbound = Proposition.dynamicallyEstimateUnboundVariablePenalty(argument);
          if (unbound == 1.0) {
            fanout = 1.0;
            nofboundargs = argument.arguments.length();
          }
          else {
            fanout = Proposition.dynamicallyEstimateGoalFanout(argument);
            nofboundargs = Proposition.countBoundArguments(argument);
          }
          if (fanout == Stella.NULL_FLOAT) {
            continue loop000;
          }
          if (fanout < 1.0) {
            fanout = 1.0;
          }
          cost = Proposition.dynamicallyEstimateGoalCost(argument);
          cost = cost * fanout * unbound;
          if ((bestcost == Stella.NULL_FLOAT) ||
              (((cost < bestcost) &&
              ((bestnofboundargs == 0) ||
               (!(nofboundargs == 0)))) ||
               ((cost >= bestcost) &&
                ((bestnofboundargs == 0) &&
                 (!(nofboundargs == 0)))))) {
            bestcost = cost;
            bestnofboundargs = nofboundargs;
            cheapestargindex = i;
            if (bestcost == 1.0) {
              break loop000;
            }
          }
        }
      }
      if (cheapestargindex > cursor) {
        argument = ((Proposition)((arguments.theArray)[cursor]));
        (arguments.theArray)[cursor] = (((Proposition)((arguments.theArray)[cheapestargindex])));
        (arguments.theArray)[cheapestargindex] = argument;
      }
    }
  }