public static Cons cppFlattenStatements(Cons statements) {
    if ((statements != null) &&
        (!(statements == Stella.NIL))) {
      { Surrogate testValue000 = Stella_Object.safePrimaryType(statements.value);

        if (testValue000 == Stella.SGT_STELLA_CONS) {
          { Cons flattenedsubtree = Stella.NIL;
            Cons flattenedtree = Stella.NIL;

            while (!(statements == Stella.NIL)) {
              flattenedsubtree = Cons.cppFlattenStatements(((Cons)(statements.value)));
              if (Stella_Object.consP(flattenedsubtree.value)) {
                flattenedtree = flattenedsubtree.reverse().concatenate(flattenedtree, Stella.NIL);
              }
              else {
                flattenedtree = Cons.cons(flattenedsubtree, flattenedtree);
              }
              statements = statements.rest;
            }
            return (flattenedtree.reverse());
          }
        }
        else if (Surrogate.subtypeOfSymbolP(testValue000)) {
          { GeneralizedSymbol testValue001 = ((GeneralizedSymbol)(statements.value));

            if ((testValue001 == Stella.SYM_STELLA_CPP_PROGN) ||
                (testValue001 == Stella.SYM_STELLA_CPP_STATEMENTS)) {
              if (statements.rest == Stella.NIL) {
                return (Stella.NIL);
              }
              else {
                return (Cons.cppFlattenStatements(statements.rest));
              }
            }
            else {
              return (statements);
            }
          }
        }
        else {
          { OutputStringStream stream000 = OutputStringStream.newOutputStringStream();

            stream000.nativeStream.print("`" + testValue000 + "' is not a valid case option");
            throw ((StellaException)(StellaException.newStellaException(stream000.theStringReader()).fillInStackTrace()));
          }
        }
      }
    }
    else {
      return (statements);
    }
  }