public static void extractOpenGoalClusters(List opengoals, List opengoalclusters) {
    { Cons allgoals = Cons.copyConsList(opengoals.theConsList);
      Cons remaininggoals = allgoals;
      Cons cursor = null;
      Proposition goal = null;
      List clusters = List.newList();
      List currentcluster = null;
      List currentclustervars = List.newList();
      boolean currentclustervarsgrewP = false;
      List unboundgoalvars = List.newList();

      loop000 : for (;;) {
        currentclustervars.clear();
        loop001 : for (;;) {
          if (remaininggoals == Stella.NIL) {
            break loop001;
          }
          if (((Proposition)(remaininggoals.value)) != null) {
            Proposition.collectUnboundGoalVariables(((Proposition)(remaininggoals.value)), currentclustervars);
          }
          if (currentclustervars.nonEmptyP()) {
            break loop001;
          }
          else {
            remaininggoals = remaininggoals.rest;
          }
        }
        if (currentclustervars.emptyP()) {
          break loop000;
        }
        currentcluster = List.newList();
        currentcluster.insert(((Proposition)(remaininggoals.value)));
        remaininggoals.firstSetter(null);
        remaininggoals = remaininggoals.rest;
        loop002 : for (;;) {
          currentclustervarsgrewP = false;
          cursor = remaininggoals;
          while (!(cursor == Stella.NIL)) {
            goal = ((Proposition)(cursor.value));
            if (goal != null) {
              unboundgoalvars.clear();
              Proposition.collectUnboundGoalVariables(goal, unboundgoalvars);
              { boolean foundP000 = false;

                { PatternVariable var = null;
                  Cons iter000 = unboundgoalvars.theConsList;

                  loop004 : for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
                    var = ((PatternVariable)(iter000.value));
                    if (currentclustervars.memberP(var)) {
                      foundP000 = true;
                      break loop004;
                    }
                  }
                }
                if (foundP000) {
                  currentcluster.push(goal);
                  cursor.firstSetter(null);
                  { PatternVariable var = null;
                    Cons iter001 = unboundgoalvars.theConsList;

                    for (;!(iter001 == Stella.NIL); iter001 = iter001.rest) {
                      var = ((PatternVariable)(iter001.value));
                      if (!currentclustervars.memberP(var)) {
                        currentclustervars.insert(var);
                        currentclustervarsgrewP = true;
                      }
                    }
                  }
                }
              }
            }
            cursor = cursor.rest;
          }
          if (!currentclustervarsgrewP) {
            break loop002;
          }
        }
        clusters.push(currentcluster.reverse());
      }
      currentclustervars.free();
      if (clusters.length() >= 2) {
        opengoals.clear();
        opengoals.theConsList = allgoals.remove(null);
        { List cluster = null;
          Cons iter002 = clusters.reverse().theConsList;
          Cons collect000 = null;

          for (;!(iter002 == Stella.NIL); iter002 = iter002.rest) {
            cluster = ((List)(iter002.value));
            if (collect000 == null) {
              {
                collect000 = Cons.cons(cluster, Stella.NIL);
                if (opengoalclusters.theConsList == Stella.NIL) {
                  opengoalclusters.theConsList = collect000;
                }
                else {
                  Cons.addConsToEndOfConsList(opengoalclusters.theConsList, collect000);
                }
              }
            }
            else {
              {
                collect000.rest = Cons.cons(cluster, Stella.NIL);
                collect000 = collect000.rest;
              }
            }
          }
        }
      }
      else {
        if (currentcluster != null) {
          currentcluster.free();
        }
      }
      clusters.free();
    }
  }