* @param index
   * @return Cons
   */
  public static Cons consTreeNthRest(Cons tree, Cons index) {
    { Stella_Object result = tree;
      int nofindices = index.length();

      { int i = Stella.NULL_INTEGER;
        Cons iter000 = index;
        int j = Stella.NULL_INTEGER;
        int iter001 = 1;

        for (;!(iter000 == Stella.NIL); iter000 = iter000.rest, iter001 = iter001 + 1) {
          i = ((IntegerWrapper)(iter000.value)).wrapperValue;
          j = iter001;
          if (Stella_Object.safePrimaryType(result) == Stella.SGT_STELLA_CONS) {
            { Cons result000 = ((Cons)(result));

              tree = result000;
            }
          }
          else {
            return (null);
          }
          if (j == nofindices) {
            result = tree.nthRest(i);
          }
          else {
            result = tree.nth(i);
          }
        }
      }
      return (((Cons)(result)));
    }
  }