public static Cons findMatchingCaseVars(Cons clause, List antecedent, List generatedVariables) {
    { Stella_Object predicate = clause.value;
      int arity = clause.length();

      { Cons ant = null;
        Cons iter000 = antecedent.theConsList;

        for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
          ant = ((Cons)(iter000.value));
          { Cons realAnt = ant;

            if (Logic.$LOG_ANTECEDENT_CONSTRUCTION$) {
              System.out.println("   Comparing " + clause + " to " + realAnt);
            }
            if (Stella_Object.eqlP(realAnt.value, predicate) &&
                (Logic.parametersAlignedP(clause, realAnt, generatedVariables) &&
                 (realAnt.length() == arity))) {
              { Cons subs = Stella.NIL;

                { Stella_Object var1 = null;
                  Cons iter001 = clause.rest;
                  Stella_Object var2 = null;
                  Cons iter002 = realAnt.rest;
                  Cons collect000 = null;

                  for (;(!(iter001 == Stella.NIL)) &&
                            (!(iter002 == Stella.NIL)); iter001 = iter001.rest, iter002 = iter002.rest) {
                    var1 = iter001.value;
                    var2 = iter002.value;
                    generatedVariables.push(var2);
                    if (collect000 == null) {
                      {
                        collect000 = Cons.cons(Cons.consList(Cons.cons(var2, Cons.cons(var1, Stella.NIL))), Stella.NIL);
                        if (subs == Stella.NIL) {
                          subs = collect000;
                        }
                        else {
                          Cons.addConsToEndOfConsList(subs, collect000);
                        }
                      }
                    }
                    else {
                      {
                        collect000.rest = Cons.cons(Cons.consList(Cons.cons(var2, Cons.cons(var1, Stella.NIL))), Stella.NIL);
                        collect000 = collect000.rest;
                      }
                    }
                  }
                }
                if (Logic.$LOG_ANTECEDENT_CONSTRUCTION$) {
                  System.out.println("   Found match: " + subs);
                }
                return (subs);
              }
            }
          }
        }
      }
      return (Stella.NIL);
    }
  }