public static ControlFrame helpFindDuplicatedGoal(ControlFrame goalframe, Object [] MV_returnarray) {
    { Proposition atomicgoal = goalframe.proposition;
      Cons bindings = goalframe.goalBindings;
      int depth = 1;
      ControlFrame firstgoalframe = null;
      Proposition testgoal = null;
      ControlFrame testframe = null;
      ControlFrame restartframe = null;
      int restartdepth = Stella.NULL_INTEGER;

      testframe = ((QueryIterator)(Logic.$QUERYITERATOR$.get())).baseControlFrame.down;
      for (;;) {
        testgoal = testframe.proposition;
        { boolean testValue000 = false;

          testValue000 = testgoal != null;
          if (testValue000) {
            testValue000 = testgoal.operator == atomicgoal.operator;
            if (testValue000) {
              testValue000 = testframe.reversePolarityP == goalframe.reversePolarityP;
              if (testValue000) {
                if ((bindings == null) &&
                    (testframe.goalBindings == null)) {
                  testValue000 = true;
                }
                else {
                  {
                    testValue000 = bindings != null;
                    if (testValue000) {
                      testValue000 = testframe.goalBindings != null;
                      if (testValue000) {
                        { boolean alwaysP000 = true;

                          { Stella_Object b1 = null;
                            Cons iter000 = bindings;
                            Stella_Object b2 = null;
                            Cons iter001 = testframe.goalBindings;

                            loop001 : for (;(!(iter000 == Stella.NIL)) &&
                                      (!(iter001 == Stella.NIL)); iter000 = iter000.rest, iter001 = iter001.rest) {
                              b1 = iter000.value;
                              b2 = iter001.value;
                              if (!Stella_Object.eqlP(b1, b2)) {
                                alwaysP000 = false;
                                break loop001;
                              }
                            }
                          }
                          testValue000 = alwaysP000;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          if (testValue000) {
            if (firstgoalframe == null) {
              firstgoalframe = testframe;
            }
            else {
              { ControlFrame _return_temp = firstgoalframe;

                MV_returnarray[0] = restartframe;
                MV_returnarray[1] = IntegerWrapper.wrapInteger(restartdepth);
                return (_return_temp);
              }
            }
          }
        }
        restartframe = testframe;
        restartdepth = depth;
        testframe = testframe.down;
        depth = depth + 1;
        if (testframe == null) {
          { ControlFrame _return_temp = null;

            MV_returnarray[0] = null;
            MV_returnarray[1] = IntegerWrapper.wrapInteger(Stella.NULL_INTEGER);
            return (_return_temp);
          }
        }
      }
    }
  }