public static Cons walkTypecaseTree(Cons tree, Object [] MV_returnarray) {
    { Stella_Object testtree = tree.rest.value;
      StandardObject testexpressiontype = null;
      Symbol testvariable = null;
      Cons expandedcases = Stella.NIL;
      boolean needcastP = Stella_Object.symbolP(testtree) &&
          (((Symbol)(testtree)).lookupGlobalVariable() == null);
      List precedingclausetypes = List.newList();

      if (needcastP) {
        testvariable = ((Symbol)(testtree));
      }
      { Object [] caller_MV_returnarray = new Object[1];

        testtree = Stella_Object.walkATree(testtree, caller_MV_returnarray);
        testexpressiontype = ((StandardObject)(caller_MV_returnarray[0]));
      }
      tree.secondSetter(testtree);
      testexpressiontype = StandardObject.typeSpecToBaseType(testexpressiontype);
      if (Surrogate.unknownTypeP(((Surrogate)(testexpressiontype)))) {
        testexpressiontype = Stella.SGT_STELLA_UNKNOWN;
      }
      tree.secondSetter(Stella_Object.sysTree(testtree, testexpressiontype, new Object[1]));
      if (needcastP) {
        { Stella_Object casetree = null;
          Cons iter000 = tree.rest.rest;

          for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
            casetree = iter000.value;
            if (Stella_Object.safePrimaryType(casetree) == Stella.SGT_STELLA_CONS) {
              { Cons casetree000 = ((Cons)(casetree));

                { Stella_Object typetree = casetree000.value;

                  if (Stella_Object.safePrimaryType(typetree) == Stella.SGT_STELLA_CONS) {
                    { Cons typetree000 = ((Cons)(typetree));

                      casetree000.firstSetter(typetree000.value);
                      expandedcases = Cons.cons(casetree000, expandedcases);
                      { Stella_Object type = null;
                        Cons iter001 = typetree000.rest;

                        for (;!(iter001 == Stella.NIL); iter001 = iter001.rest) {
                          type = iter001.value;
                          expandedcases = Cons.cons(Cons.cons(type, ((Cons)(((Cons)(Stella_Object.copyConsTree(casetree000.rest))))).concatenate(Stella.NIL, Stella.NIL)), expandedcases);
                        }
                      }
                    }
                  }
                  else {
                    expandedcases = Cons.cons(casetree000, expandedcases);
                  }
                }
              }
            }
            else {
              expandedcases = Cons.cons(casetree, expandedcases);
            }
          }
        }
        tree.rest.rest = expandedcases.reverse();
      }
      { Stella_Object casetree = null;
        Cons iter002 = tree.rest.rest;

        for (;!(iter002 == Stella.NIL); iter002 = iter002.rest) {
          casetree = iter002.value;
          if (Stella_Object.safePrimaryType(casetree) == Stella.SGT_STELLA_CONS) {
            { Cons casetree000 = ((Cons)(casetree));

              { Stella_Object typetree = casetree000.value;

                { Surrogate testValue000 = Stella_Object.safePrimaryType(typetree);

                  if (Surrogate.subtypeOfSymbolP(testValue000)) {
                    { Symbol typetree000 = ((Symbol)(typetree));

                      if (!(Stella.stringEqlP(typetree000.symbolName, "OTHERWISE"))) {
                        { Surrogate type = StandardObject.typeSpecToBaseType(typetree000.yieldTypeSpecifier());

                          Surrogate.verifyTypecaseClauseType(((Surrogate)(testexpressiontype)), type, precedingclausetypes, casetree000);
                          casetree000.firstSetter(type);
                          type = type.typeToWrappedType();
                          if (needcastP &&
                              (!(casetree000.rest == Stella.NIL))) {
                            casetree000.rest = Symbol.yieldCastedTypecaseClauseTrees(testvariable, type, casetree000.rest);
                          }
                        }
                      }
                    }
                  }
                  else if (Surrogate.subtypeOfSurrogateP(testValue000)) {
                    { Surrogate typetree000 = ((Surrogate)(typetree));

                      if (!(Stella.stringEqlP(typetree000.symbolName, "OTHERWISE"))) {
                        { Surrogate type = StandardObject.typeSpecToBaseType(typetree000.yieldTypeSpecifier());

                          Surrogate.verifyTypecaseClauseType(((Surrogate)(testexpressiontype)), type, precedingclausetypes, casetree000);
                          casetree000.firstSetter(type);
                          type = type.typeToWrappedType();
                          if (needcastP &&
                              (!(casetree000.rest == Stella.NIL))) {
                            casetree000.rest = Symbol.yieldCastedTypecaseClauseTrees(testvariable, type, casetree000.rest);
                          }
                        }
                      }
                    }
                  }
                  else if (testValue000 == Stella.SGT_STELLA_CONS) {
                    { Cons typetree000 = ((Cons)(typetree));

                      { ConsIterator it = typetree000.allocateIterator();

                        while (it.nextP()) {
                          if (Stella_Object.consP(it.value)) {
                            { Object old$PrintreadablyP$000 = Stella.$PRINTREADABLYp$.get();

                              try {
                                Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
                                Stella.signalTranslationError();
                                if (!(Stella.suppressWarningsP())) {
                                  Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
                                  {
                                    Stella.STANDARD_ERROR.nativeStream.println();
                                    Stella.STANDARD_ERROR.nativeStream.println(" Illegal type expression in 'typecase': `" + Stella_Object.deUglifyParseTree(typetree000) + "'.");
                                  }
;
                                }

                              } finally {
                                Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$000);
                              }
                            }
                            return (Stella_Object.walkDontCallMeTree(tree, Stella.SGT_STELLA_VOID, MV_returnarray));
                          }
                          it.valueSetter(StandardObject.typeSpecToBaseType(it.value.yieldTypeSpecifier()));
                          Surrogate.verifyTypecaseClauseType(((Surrogate)(testexpressiontype)), ((Surrogate)(it.value)), precedingclausetypes, casetree000);
                        }
                      }
                    }
                  }
                  else {
                    { Object old$PrintreadablyP$001 = Stella.$PRINTREADABLYp$.get();

                      try {
                        Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
                        Stella.signalTranslationError();
                        if (!(Stella.suppressWarningsP())) {
                          Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
                          {
                            Stella.STANDARD_ERROR.nativeStream.println();
                            Stella.STANDARD_ERROR.nativeStream.println(" Illegal type expression in 'typecase': `" + Stella_Object.deUglifyParseTree(typetree) + "'.");
                          }
;
                        }

                      } finally {
                        Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$001);
                      }
                    }
                    return (Stella_Object.walkDontCallMeTree(tree, Stella.SGT_STELLA_VOID, MV_returnarray));
                  }
                }
              }
            }
          }
          else {
            { Object old$PrintreadablyP$002 = Stella.$PRINTREADABLYp$.get();

              try {
                Native.setBooleanSpecial(Stella.$PRINTREADABLYp$, true);
                Stella.signalTranslationError();
                if (!(Stella.suppressWarningsP())) {
                  Stella.printErrorContext(">> ERROR: ", Stella.STANDARD_ERROR);
                  {
                    Stella.STANDARD_ERROR.nativeStream.println();
                    Stella.STANDARD_ERROR.nativeStream.println(" Illegal case expression in 'typecase': `" + Stella_Object.deUglifyParseTree(casetree) + "'.");
                  }
;
                }

              } finally {
                Stella.$PRINTREADABLYp$.set(old$PrintreadablyP$002);
              }
            }
            return (Stella_Object.walkDontCallMeTree(tree, Stella.SGT_STELLA_VOID, MV_returnarray));
          }
        }
      }
      return (Cons.walkNonBuiltInCaseTree(Cons.list$(Cons.cons(Stella.SYM_STELLA_CASE, Cons.cons(Cons.list$(Cons.cons(Stella.SYM_STELLA_SAFE_PRIMARY_TYPE, Cons.cons(tree.rest.value, Cons.cons(Stella.NIL, Stella.NIL)))), Cons.cons(tree.rest.rest.concatenate(Stella.NIL, Stella.NIL), Stella.NIL)))), Stella.SYM_STELLA_SUBTYPE_OFp, MV_returnarray));
    }
  }