#include <perms.h>

//          Edinburgh IMP77 Compiler - Version 8.4
//
//     1
//     2  !*   Title      :  XII
//     3  !*   Version    :  I
//     4  !*   Date       :  29 June 1984
//     5  !*   Description:  Tests the ability to raise events within a program
//     6  !*                 both in the standard procedures etc and by the user.
//     7
//     8
//     9  %Begin

int main(int argc, char **argv) { /*%begin*/
  _imp_initialise(argc, argv);

  //    10     %Switch   Trap (0 : 15)

  int TRAP_index;
  int TRAP_line;
  char *TRAP_file;
  static const void *TRAP[16] = {&&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_default,
                                 &&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_default,
                                 &&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_10,      &&case_TRAP_default,
                                 &&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_default, &&case_TRAP_15};

  //    11     %Integer  Sub

  int SUB;

  //    12
  //    13  %owninteger failures=0

  static int FAILURES = 0;

  //    14
  //    15  %routine pass

  void PASS(void) {
    //    16    printstring("Pass: ")

    _imp_PRINTSTRING(_imp_str_literal("Pass: "));

    //    17  %end

    return;
  } /* end of PASS */

  //    18  %routine fail

  void FAIL(void) {
    //    19    printstring("FAIL: ")

    _imp_PRINTSTRING(_imp_str_literal("FAIL: "));

    //    20    failures = failures+1

    FAILURES = FAILURES + 1;

    //    21  %end

    return;
  } /* end of FAIL */

  //    22
  //    23     %On %Event 0, 10, 13, 15 %Start

  if (!_imp_on_event(0, 10, 13, 15)) goto L_0001;

    //    24
    //    25         Sub = Event_Sub {Event}

  SUB = _imp_EVENT().SUB;

  //    26         -> Trap (Event_Event)

  TRAP_line = __LINE__;
  TRAP_file = __FILE__;
  TRAP_index = _imp_EVENT().EVENT;
  goto case_TRAP_dispatch;

  //    27
  //    28         Trap(10):     { Trap an event raised inside a %On block

case_TRAP_10:;

//    29                       { Raised inside local routine 'Eventful'.
//    30
//    31         %If Sub = 116 %c

  if (SUB != 116) goto L_0003;
  _imp_PRINTSTRING(_imp_str_literal("Trapped an event inside an %ON block"));
  goto L_0004;
L_0003:;
  _imp_PRINTSTRING(_imp_str_literal("Error in _Sub Event field for event 10"));
L_0004:;

//    32+            %then Print String ("Trapped an event inside an %ON block")  %c
//    33+            %else Print String ("Error in _Sub Event field for event 10")
//    34         New Line

  _imp_NEWLINE();

  //    35         -> Resume2

  goto U_1000;

  //    36
  //    37         Trap(15):     { Trapping events inside routines.

case_TRAP_15:;

//    38
//    39         Print String ("Trapped event inside a ")

  _imp_PRINTSTRING(_imp_str_literal("Trapped event inside a "));

  //    40         %If Sub = 115 %then %Start

  if (SUB != 115) goto L_0005;

    //    41             Print String ("local routine.")

  _imp_PRINTSTRING(_imp_str_literal("local routine."));

  //    42             New Line

  _imp_NEWLINE();

  //    43             %If Event_Info{Extra} = 20 %then pass %else fail

  if (_imp_EVENT().INFO != 20) goto L_0006;
  PASS();
  goto L_0007;
L_0006:;
  FAIL();
L_0007:;

//    44             Print String ("Event_Extra field correctly assigned.")

  _imp_PRINTSTRING(_imp_str_literal("Event_Extra field correctly assigned."));

  //    45             New Line

  _imp_NEWLINE();

  //    46             -> Resume3

  goto U_1001;

  //    47         %Finish %else %if Sub = 118 %then %start

L_0005:;
  if (SUB != 118) goto L_0008;

    //    48             Print String ("nested, deeply recursed routine.")

  _imp_PRINTSTRING(_imp_str_literal("nested, deeply recursed routine."));

  //    49             New Line

  _imp_NEWLINE();

  //    50             -> Resume4

  goto U_1002;

  //    51         %Finish

L_0008:;

//    52
//    53         TRAP(*):

case_TRAP_default:;

//    54            Print String("FAIL: Unexpected event")

  _imp_PRINTSTRING(_imp_str_literal("FAIL: Unexpected event"));

  //    55            write(event_event,1);  newline

  _imp_WRITE(_imp_EVENT().EVENT, 1);
  _imp_NEWLINE();

  //    56            %stop

  _imp_stop(0);

  //    57      %Finish

L_0001:;

//    58
//    59
//    60     %Routine  Test Standard Events

  void TESTSTANDARDEVENTS(void) {
    //    61
    //    62         !*  This routine forces the standard events to be raised to
    //    63         !*  test their validity.
    //    64
    //    65         %Label   Catch

    // __label__ /* block-scoped label (GCC) */ CATCH;

    //    66
    //    67         %Integer J

    int J;

    //    68         %Integer K

    int K;

    //    69         %Integer C

    int C;

    //    70         %Integer A

    int A;

    //    71
    //    72         %Integer Start = 0

    int START;
    START = 0;

    //    73
    //    74         %Integer Zero = 0

    int ZERO;
    ZERO = 0;

    //    75         %Integer Minus = -1

    int MINUS;
    MINUS = -1;

    //    76         %Integer Unassigned

    int UNASSIGNED;

    //    77
    //    78         %String(255) S, T

    _imp_string255 S;
    _imp_string255 T;

    //    79
    //    80         %Switch  EN (0 : 100)    { Event Number = Event * 10 + Sub

    int EN_index;
    int EN_line;
    char *EN_file;
    static const void *EN[101] = {
        &&case_EN_0,       &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_11,      &&case_EN_default, &&case_EN_13,      &&case_EN_14,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_21,      &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_33,      &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_41,      &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_51,      &&case_EN_52,      &&case_EN_53,      &&case_EN_54,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_62,      &&case_EN_default, &&case_EN_default,
        &&case_EN_65,      &&case_EN_66,      &&case_EN_67,      &&case_EN_default, &&case_EN_default,
        &&case_EN_70,      &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_81,      &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_90,      &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default, &&case_EN_default,
        &&case_EN_default};

    //    81
    //    82
    //    83         %On %Event 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  %Start

    if (!_imp_on_event(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) goto L_0009;

      //    84
      //    85             Select Output ({1}0) %if K = 90   { Revert back to old stream.

    if (K != 90) goto L_000A;
    _imp_SELECTOUTPUT(0);
  L_000A:;

  //    86
  //    87             %If Event_Event = K // 10 %and Event_Sub {Event} = Rem (K, 10) %Start

    if (_imp_EVENT().EVENT != ((long)K / (long)10)) goto L_000B;
    if (_imp_EVENT().SUB != _imp_REM(K, 10)) goto L_000B;

      //    88                Print String ("Successfully trapped:  Event =")

    _imp_PRINTSTRING(_imp_str_literal("Successfully trapped:  Event ="));

    //    89                Write (K // 10, 1)

    _imp_WRITE(((long)K / (long)10), 1);

    //    90                Print String ("   Sub =")

    _imp_PRINTSTRING(_imp_str_literal("   Sub ="));

    //    91                Write (Rem (K, 10), 1)

    _imp_WRITE(_imp_REM(K, 10), 1);

    //    92                New Line

    _imp_NEWLINE();

    //    93             %finish %else %start

    goto L_000C;
  L_000B:;

  //    94                Print String ("Should have trapped:  Event =")

    _imp_PRINTSTRING(_imp_str_literal("Should have trapped:  Event ="));

    //    95                Write (K // 10, 1)

    _imp_WRITE(((long)K / (long)10), 1);

    //    96                Print String ("   Sub =")

    _imp_PRINTSTRING(_imp_str_literal("   Sub ="));

    //    97                Write (Rem (K, 10), 1)

    _imp_WRITE(_imp_REM(K, 10), 1);

    //    98                New Line

    _imp_NEWLINE();

    //    99                Print String ("Instead trapped:  Event =")

    _imp_PRINTSTRING(_imp_str_literal("Instead trapped:  Event ="));

    //   100                Write (Event_Event, 1)

    _imp_WRITE(_imp_EVENT().EVENT, 1);

    //   101                Print String ("   Sub =")

    _imp_PRINTSTRING(_imp_str_literal("   Sub ="));

    //   102                Write (Event_Sub {Event}, 1)

    _imp_WRITE(_imp_EVENT().SUB, 1);

    //   103                New Line

    _imp_NEWLINE();

    //   104            %Finish

  L_000C:;

  //   105            Start = K + 1

    START = K + 1;

    //   106
    //   107         %Finish

  L_0009:;

  //   108
  //   109
  //   110          %For K = Start, 1, 100 %cycle

  // %for K = START, 1, 100 %cycle
    {
      int _initial = START;
      if (invalid_for_loop(_initial, 1, 100)) _imp_signal(5, 1, 0, "Illegal cycle K = START, 1, 100");
      K = _initial - (1);
    L_000D:
      if (K == 100) goto L_000E;
      K += 1;

      //   111
      //   112  write(k,1);newline

      _imp_WRITE(K, 1);
      _imp_NEWLINE();

      //   113             -> EN(K)

      EN_line = __LINE__;
      EN_file = __FILE__;
      EN_index = K;
      goto case_EN_dispatch;

      //   114
      //   115
      //   116             EN(0):   { Normal Termination by the %STOP Instruction.

    case_EN_0:;

    //   117
    //   118                      %Stop

      _imp_stop(0);

      //   119                      -> Catch

      goto U_1003;

      // ?access
      //   120
      //   121
      //   122
      //   123             EN(11):  { Integer Overflow

    case_EN_11:;

    //   124
    //   125                      J = 2147483600       { Two to the power of 32.

      J = 2147483600;

      //   126                      C = J * 3

      C = J * 3;

      //   127                      -> Catch

      goto U_1003;

      //   128
      //   129
      //   130
      //   131             EN(13):  { String Overflow.

    case_EN_13:;

    //   132
    //   133                      S = "1234567890"

      _imp_strncpy(/*?*/ &S, ({
                     __typeof__(_imp_string255) tmp; /*B*/
                     tmp = _imp_str_literal("1234567890");
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   134                      T = ""

      _imp_strncpy(/*?*/ &T, ({
                     __typeof__(_imp_string255) tmp; /*B*/
                     tmp = _imp_str_literal("");
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   135                      T = T . S  %for J = 1, 1, 30

      // %for J = 1, 1, 30 %cycle
      {
        J = 0;
      L_0011:
        if (J == 30) goto L_0012;
        J += 1;

        _imp_strncpy(/*?*/ &T, ({
                       __typeof__(_imp_string255) tmp; /*B*/
                       tmp = *({
                         _imp_string255 tmp = _imp_join((_imp_string *)/*?*/ &T, (_imp_string *)/*?*/ &S);
                         (_imp_string255 *)&tmp;
                       });
                       (void *)&tmp;
                     }),
                     /*max:*/ 255);

        goto L_0011;
      }

    L_0012:;

    //   136                      -> Catch

      goto U_1003;

      //   137
      //   138
      //   139             EN(14):  { Division by zero.

    case_EN_14:;

    //   140
    //   141                      J = Minus // Zero

      J = ((long)MINUS / (long)ZERO);

      //   142                      -> Catch

      goto U_1003;

      //   143
      //   144
      //   145
      //   146          EN(21):  { Store Space Exhausted

    case_EN_21:;

    //   147
    //   148                   %Begin

      { /*%begin*/

        //   149                      %Integer %Array Temp (1 : 10000000)

        int TEMP[10000000];

        //   150
        //   151                      J = 10000000

        J = 10000000;

        //   152                      Temp (J) = 1

        TEMP[J - 1] = 1;

        //   153                    %End

        goto end_1000;
      end_1000:;
      }

      //   154                    -> Catch

      goto U_1003;

      //   155
      //   156
      //   157
      //   158          EN(33):   { Failure to open a file.

    case_EN_33:;

    //   159
    //   160                    Open Input (2, "ZZZZZ.ZZZ")   { Non-existent?

      _imp_OPENINPUT(2, _imp_str_literal("ZZZZZ.ZZZ"));

      //   161                    -> Catch

      goto U_1003;

      //   162
      //   163
      //   164
      //   165          EN(41):   { Non-numeric char for numeric input.

    case_EN_41:;

    //   166
    //   167                    Open Input (2, "Char.dat")

      _imp_OPENINPUT(2, _imp_str_literal("Char.dat"));

      //   168                    Select Input (2)

      _imp_SELECTINPUT(2);

      //   169                    Read (J)

      _imp_READ(/*?*/ &J);

      //   170                    -> Catch

      goto U_1003;

      //   171
      //   172
      //   173
      //   174          EN(51):   { Inconsistent combination of values for %For loop.

    case_EN_51:;

    //   175
    //   176                    J = 0

      J = 0;

      //   177                    A = 0

      A = 0;

      //   178                    %For C = 2, 1, J %cycle

      // %for C = 2, 1, J %cycle
      {
        int _final = J;
        if (invalid_for_loop(2, 1, _final)) _imp_signal(5, 1, 0, "Illegal cycle C = 2, 1, J");
        C = 1;
      L_0014:
        if (C == _final) goto L_0015;
        C += 1;

        //   179                       A = A + 1

        A = A + 1;

        //   180                       %Exit %if A = 10   { Break an infinite loop.

        if (A != 10) goto L_0016;
        goto L_0015;
      L_0016:;

      //   181                    %Repeat

        goto L_0014;
      }

    L_0015:;

    //   182                    -> Catch

      goto U_1003;

      //   183
      //   184
      //   185
      //   186
      //   187          EN(52):   { Illegal exponent for exponentiation.

    case_EN_52:;

    //   188
    //   189                    J = -4

      J = -4;

      //   190                    C = 2 ^^ J

      C = _imp_IEXP(2, J);

      //   191                    -> Catch

      goto U_1003;

      //   192
      //   193
      //   194
      //   195          EN(53):   { Upper bound less than lower in array declaration.

    case_EN_53:;

    //   196
    //   197                    J = 20

      J = 20;

      //   198                    %Begin

      { /*%begin*/

        //   199                       %Integer %Array  Temp (40 : J)

        int TEMP[J - 40 + 1];

        //   200
        //   201                       J = 35

        J = 35;

        //   202                       Temp(J) = 10

        TEMP[J - 40] = 10;

        //   203                    %End

        goto end_1001;
      end_1001:;
      }

      //   204                    -> Catch

      goto U_1003;

      //   205
      //   206
      //   207
      //   208          EN(54):   { First index greater than second for SUB STRING.

    case_EN_54:;

    //   209
    //   210                    S = "1234567890"

      _imp_strncpy(/*?*/ &S, ({
                     __typeof__(_imp_string255) tmp; /*B*/
                     tmp = _imp_str_literal("1234567890");
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   211                    J = 20

      J = 20;

      //   212                    S = Sub String (S, J, 5)

      _imp_strncpy(/*?*/ &S, ({
                     __typeof__(_imp_string255) tmp; /*B*/
                     tmp = _imp_SUBSTRING((_imp_string255 *)/*p*/ /*?*/ &S, J, 5);
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   213                    -> Catch

      goto U_1003;

      //   214
      //   215
      //   216
      //   217          EN(62):   { Array index out of bounds.

    case_EN_62:;

    //   218
    //   219                    J = 20

      J = 20;

      //   220                    %Begin

      { /*%begin*/

        //   221                       %Integer %Array  Temp (0 : J)

        int TEMP[J + 1];

        //   222
        //   223                       Temp (J + 5) = 29

        TEMP[J + 5] = 29;

        //   224                    %End

        goto end_1002;
      end_1002:;
      }

      //   225                    -> Catch

      goto U_1003;

      //   226
      //   227
      //   228
      //   229
      //   230
      //   231          EN(65):   { CHAR NO index out of range 1 to max string length.

    case_EN_65:;

    //   232
    //   233                    S = "1234567890"

      _imp_strncpy(/*?*/ &S, ({
                     __typeof__(_imp_string255) tmp; /*B*/
                     tmp = _imp_str_literal("1234567890");
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   234                    J = 20

      J = 20;

      //   235                    C = Char No (S, J)

      C = *_imp_CHARNO((_imp_string255 *)/*p*/ /*?*/ &S, J);

      //   236                    -> Catch

      goto U_1003;

      //   237
      //   238
      //   239
      //   240          EN(66):   { Value out of range for TO STRING.

    case_EN_66:;

    //   241
    //   242                    S = To String (Minus)

      _imp_strncpy(/*?*/ &S, ({
                     __typeof__(_imp_string1) tmp; /*B*/
                     tmp = _imp_TOSTRING(MINUS);
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   243                    -> Catch

      goto U_1003;

      //   244
      //   245
      //   246
      //   247          EN(67):   { Value out of range of OPEN and SELECT.

    case_EN_67:;

    //   248
    //   249                    SELECT INPUT (20)

      _imp_SELECTINPUT(20);

      //   250                    -> Catch

      goto U_1003;

      //   251
      //   252
      //   253
      //   254          EN(70):   { String Resolution error.

    case_EN_70:;

    //   255
    //   256                    S = "ABCD"

      _imp_strncpy(/*?*/ &S, ({
                     __typeof__(_imp_string255) tmp; /*B*/
                     tmp = _imp_str_literal("ABCD");
                     (void *)&tmp;
                   }),
                   /*max:*/ 255);

      //   257                    S -> S.("EFGH")

      if (!_imp_resolve(*({
            _imp_string255 tmp = S;
            (_imp_string255 *)&tmp;
          }),
                        (_imp_string255 *)/*?*/ &S, *({
                          _imp_string tmp = _imp_str_literal("EFGH");
                          (_imp_string255 *)&tmp;
                        }),
                        0 /*NULL*/))
        _imp_signal(7, 1, 0, "string resolution fails");
        //   258                    -> Catch

      goto U_1003;

      //   259
      //   260
      //   261
      //   262          EN(81):   { Unassigned variable.

    case_EN_81:;

    //   263
    //   264                    J = Unassigned

      J = UNASSIGNED;

      //   265                    -> Catch

      goto U_1003;

      //   266
      //   267
      //   268
      //   269          EN(90):   { End of Input

    case_EN_90:;

    //   270
    //   271                    Open Output (2, "Null.dat")

      _imp_OPENOUTPUT(2, _imp_str_literal("Null.dat"));

      //   272                    Select Output (2)

      _imp_SELECTOUTPUT(2);

      //   273                    Close Output

      _imp_CLOSEOUTPUT();

      //   274                    Open Input (2, "Null.dat")

      _imp_OPENINPUT(2, _imp_str_literal("Null.dat"));

      //   275                    Select Input (2)

      _imp_SELECTINPUT(2);

      //   276                    Read (J)

      _imp_READ(/*?*/ &J);

      //   277                    -> Catch

      goto U_1003;

      //   278
      //   279
      //   280
      //   281             Catch:  Print String ("FAILED to trap:  Event =")

    U_1003:;
      _imp_PRINTSTRING(_imp_str_literal("FAILED to trap:  Event ="));

      //   282                     Write (K // 10, 1)

      _imp_WRITE(((long)K / (long)10), 1);

      //   283                     Print String ("   Sub =")

      _imp_PRINTSTRING(_imp_str_literal("   Sub ="));

      //   284                     Write (Rem (K, 10), 1)

      _imp_WRITE(_imp_REM(K, 10), 1);

      //   285                     New Line

      _imp_NEWLINE();

      //   286
      //   287
      //   288             EN(*):

    case_EN_default:;

    //   289
    //   290          %Repeat

      goto L_000D;
    }

  L_000E:;

  //   291
  //   292
  //   293      %End   { of Test Standard Events

    return;

  case_EN_dispatch:
    if (EN_index < 0 || EN_index > 100)
      _imp_signalf(6, 3, EN_index, "->EN(%d) out of bounds at %s line %d", EN_index, EN_file, EN_line);
    goto *EN[EN_index - 0];
  } /* end of TESTSTANDARDEVENTS */

  //   294
  //   295
  //   296
  //   297     %Routine  Eventful (%Integer Trap)

  void EVENTFUL(int TRAP) {
    //   298
    //   299         !*  Tests the trapping of events within a routine block.
    //   300         !*  Does the control fall through the bottom of the %On
    //   301         !*  block?  If a trap is not present will control be passed
    //   302         !*  to the parent block?
    //   303
    //   304         %Integer E = 14

    int E;
    E = 14;

    //   305
    //   306         %On %Event 14 %Start

    if (!_imp_on_event(14)) goto L_0017;

      //   307            %Signal %Event 10, 116 %if E = 14 %and Trap = 1

    if (E != 14) goto L_0018;
    if (TRAP != 1) goto L_0018;
    _imp_signal(10, 116, 0, "");
  L_0018:;

  //   308            E = E + 1

    E = E + 1;

    //   309         %Finish

  L_0017:;

  //   310
  //   311         %Signal %Event 14  %if E = 14

    if (E != 14) goto L_0019;
    _imp_signal(14, 0, 0, "");
  L_0019:;

  //   312         %Signal %Event 15, 115, 20        { Test the _Extra field.

    _imp_signal(15, 115, 20, "");

    //   313
    //   314     %End  { of Eventful

    return;
  } /* end of EVENTFUL */
  auto void INC(int D);

  //   315
  //   316
  //   317
  //   318
  //   319
  //   320     !*   The following set of routines test various aspects of
  //   321     !*  procedures.  Firstly, it checks whether routines nested
  //   322     !*  to depth four can be handled.  Then it checks %Routine %Specs
  //   323     !*  and mutual recursion.  Finally, at a very deep recursion and
  //   324     !*  level of nesting, the signalling of an event.  This severe
  //   325     !*  test checks the possibility of stack corruption and automatic
  //   326     !*  %Return from a great, complex depth.
  //   327
  //   328
  //   329     %Routine %Spec  Inc (%Integer D)
  //   330
  //   331
  //   332     %Routine  Inc2 (%Integer D)

  void INC2(int D) {
    //   333
    //   334         %Routine  Inc3 (%Integer D)

    void INC3(int D) {
      //   335
      //   336             %Routine  Inc4 (%Integer D)

      void INC4(int D) {
        //   337
        //   338                 %Routine  Inc5 (%Integer D)

        void INC5(int D) {
          //   339
          //   340                     %If D > 400 %then %Start

          if (D <= 400) goto L_001A;

            //   341                        %Signal %Event 15, 118

          _imp_signal(15, 118, 0, "");

          //   342                        Print String ("FAIL: To raise a deep event.")

          _imp_PRINTSTRING(_imp_str_literal("FAIL: To raise a deep event."));

          // ?access
          //   343                        New Line

          _imp_NEWLINE();

          //   344                        %Return

          return;

          //   345                     %Finish

        L_001A:;

        //   346                     Inc (D+1)    { Mutual Recursion.

          INC(D + 1);

          //   347
          //   348                 %End  { of Inc5

          return;
        } /* end of INC5 */

        //   349
        //   350                 Inc5 (D+1)

        INC5(D + 1);

        //   351
        //   352             %End  { of Inc4

        return;
      } /* end of INC4 */

      //   353
      //   354             Inc4 (D+1)

      INC4(D + 1);

      //   355
      //   356         %End  { of Inc3

      return;
    } /* end of INC3 */

    //   357
    //   358         Inc3 (D+1)

    INC3(D + 1);

    //   359
    //   360     %End  { of Inc2

    return;
  } /* end of INC2 */

  //   361
  //   362
  //   363
  //   364
  //   365     %Routine  Inc (%Integer D)

  void INC(int D) {
    //   366
    //   367         Inc2 (D+1)

    INC2(D + 1);

    //   368
    //   369     %End  { of Inc

    return;
  } /* end of INC */

  //   370
  //   371
  //   372
  //   373     %if cliparam = "" %start

  if (_imp_strcmp((_imp_string *)/*?*/ &_imp_CLIPARAM(), (_imp_string *)/*?*/ _imp_str_literal_ptr("")) != 0)
    goto L_001B;

    //   374       Open Output (1, "/tmp/EVENTS.out")

  _imp_OPENOUTPUT(1, _imp_str_literal("/tmp/EVENTS.out"));

  //   375     %else

  goto L_001C;
L_001B:;

//   376       print string("Writing to ".cliparam); newline

  _imp_PRINTSTRING(
      *({
        __typeof__(_imp_string255) tmp = *({
          _imp_string255 tmp = _imp_join((_imp_string *)/*?*/ _imp_str_literal_ptr("Writing to "), ({
                                           __typeof__(_imp_string255) tmp; /*E*/
                                           tmp = _imp_CLIPARAM();
                                           (void *)&tmp;
                                         }));
          (_imp_string255 *)&tmp;
        }) /*q*/;
        (_imp_string255 *)&tmp;
      })
  );
  _imp_NEWLINE();

  //   377       Open Output (1, cliparam)

  _imp_OPENOUTPUT(1,
                  *({
                    __typeof__(_imp_string255) tmp = _imp_CLIPARAM() /*q*/;
                    (_imp_string255 *)&tmp;
                  })
  );

  //   378     %finish

L_001C:;

//   379     Select Output (1)

  _imp_SELECTOUTPUT(1);

  //   380
  //   381     New Lines (3)

  _imp_NEWLINES(3);

  //   382
  //   383     Print String ("Test the Ability to Raise Standard Events"); New Line

  _imp_PRINTSTRING(_imp_str_literal("Test the Ability to Raise Standard Events"));
  _imp_NEWLINE();

  //   384     Print String ("-----------------------------------------")

  _imp_PRINTSTRING(_imp_str_literal("-----------------------------------------"));

  //   385     New Lines (2)

  _imp_NEWLINES(2);

  //   386
  //   387     Test Standard Events

  TESTSTANDARDEVENTS();

  //   388
  //   389     New Lines (2)

  _imp_NEWLINES(2);

  //   390
  //   391               Eventful(1)

  EVENTFUL(1);

  //   392     Resume2:  Eventful(0)

U_1000:;
  EVENTFUL(0);

  //   393     Resume3:  Inc (1)

U_1001:;
  INC(1);

  //   394     Resume4:

U_1002:;

//   395               Print String ("Returned from a depth correctly.")

  _imp_PRINTSTRING(_imp_str_literal("Returned from a depth correctly."));

  //   396               New Lines (2)

  _imp_NEWLINES(2);

  //   397
  //   398  select output(0)

  _imp_SELECTOUTPUT(0);

  //   399  write(failures,1);  printstring(" failure(s)");  newline

  _imp_WRITE(FAILURES, 1);
  _imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
  _imp_NEWLINE();

  //   400
  //   401  %End %of %Program

  _imp_stop(0);
  return 0;

case_TRAP_dispatch:
  if (TRAP_index < 0 || TRAP_index > 15)
    _imp_signalf(6, 3, TRAP_index, "->TRAP(%d) out of bounds at %s line %d", TRAP_index, TRAP_file, TRAP_line);
  goto *TRAP[TRAP_index - 0];
end_0:;
}