#include <perms.h>
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  static int Trap_sw;
  static void *Trap[16 /*0:15*/] = {
      &&Trap_default, &&Trap_default, &&Trap_default, &&Trap_default, &&Trap_default, &&Trap_default,
      &&Trap_default, &&Trap_default, &&Trap_default, &&Trap_default, &&Trap_10,      &&Trap_default,
      &&Trap_default, &&Trap_default, &&Trap_default, &&Trap_15,
  };
  int Sub;
  static int Failures = 0;
  void Pass(void) { Printstring(_imp_str_literal("Pass: ")); }
  void Fail(void) {
    Printstring(_imp_str_literal("FAIL: "));
    Failures++;
  }
  if (_imp_on_event(0, 10, 13, 15)) {
    Sub = Event.Sub;
    goto *Trap[Trap_sw = Event.Event()];
  Trap_10:;
    if (Sub == 116)
      Printstring(_imp_str_literal("Trapped an event inside an %ON block"));
    else
      Printstring(_imp_str_literal("Error in _Sub Event field for event 10"));
    Newline();
    goto Resume2;
  Trap_15:;
    Printstring(_imp_str_literal("Trapped event inside a "));
    if (Sub == 115) {
      Printstring(_imp_str_literal("local routine."));
      Newline();
      if (Event.Info == 20)
        Pass();
      else
        Fail();
      Printstring(_imp_str_literal("Event_Extra field correctly assigned."));
      Newline();
      goto Resume3;
    } else if (Sub == 118) {
      Printstring(_imp_str_literal("nested, deeply recursed routine."));
      Newline();
      goto Resume4;
    }
  Trap_default:;
    Printstring(_imp_str_literal("FAIL: Unexpected event"));
    Write(Event.Event(), 1);
    Newline();
    exit(0);
  }
  void Teststandardevents(void) {
    __label__ Catch;
    int J;
    int K;
    int C;
    int A;
    int Start = 0;
    int Zero = 0;
    int Minus = -1;
    int Unassigned;
    _imp_string S;
    _imp_string T;
    static int En_sw;
    static void *En[101 /*0:100*/] = {
        &&En_0,       &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_11,      &&En_default, &&En_13,      &&En_14,      &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_21,      &&En_default, &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_33,      &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_41,      &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_51,      &&En_52,      &&En_53,      &&En_54,      &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_62,      &&En_default,
        &&En_default, &&En_65,      &&En_66,      &&En_67,      &&En_default, &&En_default, &&En_70,      &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_81,      &&En_default, &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_default, &&En_90,      &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
        &&En_default, &&En_default, &&En_default, &&En_default, &&En_default,
    };
    if (_imp_on_event(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) {
      if (K == 90) Selectoutput(0);
      if (Event.Event() == K / 10 && Event.Sub == Rem(K, 10)) {
        Printstring(_imp_str_literal("Successfully trapped:  Event ="));
        Write(K / 10, 1);
        Printstring(_imp_str_literal("   Sub ="));
        Write(Rem(K, 10), 1);
        Newline();
      } else {
        Printstring(_imp_str_literal("Should have trapped:  Event ="));
        Write(K / 10, 1);
        Printstring(_imp_str_literal("   Sub ="));
        Write(Rem(K, 10), 1);
        Newline();
        Printstring(_imp_str_literal("Instead trapped:  Event ="));
        Write(Event.Event(), 1);
        Printstring(_imp_str_literal("   Sub ="));
        Write(Event.Sub, 1);
        Newline();
      }
      Start = K + 1;
    }
    for (K = Start; K <= 100; K++) {
      Write(K, 1);
      Newline();
      goto *En[En_sw = K];
    En_0:;
      exit(0);
      goto Catch;
    En_11:;
      J = 2147483600;
      C = J * 3;
      goto Catch;
    En_13:;
      S = _imp_str_literal("1234567890");
      T = _imp_str_literal("");
      for (J = 1; J <= 30; J++) T = _imp_join(T, S);
      goto Catch;
    En_14:;
      J = Minus / Zero;
      goto Catch;
    En_21:;
      {
        int Temp[10000000 /*1:10000000*/];
        J = 10000000;
        Temp[J] = 1;
      }
      goto Catch;
    En_33:;
      Openinput(2, _imp_str_literal("ZZZZZ.ZZZ"));
      goto Catch;
    En_41:;
      Openinput(2, _imp_str_literal("Char.dat"));
      Selectinput(2);
      Read(J);
      goto Catch;
    En_51:;
      J = 0;
      A = 0;
      for (C = 2; C <= J; C++) {
        A++;
        if (A == 10) break;
      }
      goto Catch;
    En_52:;
      J = -4;
      C = IEXP(2, J);
      goto Catch;
    En_53:;
      J = 20;
      {
        int Temp[J - 40 + 1];
        J = 35;
        Temp[J] = 10;
      }
      goto Catch;
    En_54:;
      S = _imp_str_literal("1234567890");
      J = 20;
      S = Substring(S, J, 5);
      goto Catch;
    En_62:;
      J = 20;
      {
        int Temp[J + 1];
        Temp[J + 5] = 29;
      }
      goto Catch;
    En_65:;
      S = _imp_str_literal("1234567890");
      J = 20;
      C = *Charno(S, J);
      goto Catch;
    En_66:;
      S = Tostring(Minus);
      goto Catch;
    En_67:;
      Selectinput(20);
      goto Catch;
    En_70:;
      S = _imp_str_literal("ABCD");
      if (!_imp_resolve(S, S, _imp_str_literal("EFGH"), NULL)) _imp_signal(7, 0, 0);
      goto Catch;
    En_81:;
      J = Unassigned;
      goto Catch;
    En_90:;
      Openoutput(2, _imp_str_literal("Null.dat"));
      Selectoutput(2);
      Closeoutput();
      Openinput(2, _imp_str_literal("Null.dat"));
      Selectinput(2);
      Read(J);
      goto Catch;
    Catch:
      Printstring(_imp_str_literal("FAILED to trap:  Event ="));
      Write(K / 10, 1);
      Printstring(_imp_str_literal("   Sub ="));
      Write(Rem(K, 10), 1);
      Newline();
    En_default:;
    }
  }
  void Eventful(int Trap) {
    int E = 14;
    if (_imp_on_event(14)) {
      if (E == 14 && Trap == 1) _imp_signal(10, 116, 0, _imp_str_literal(""));
      E++;
    }
    if (E == 14) _imp_signal(14, 0, 0, _imp_str_literal(""));
    _imp_signal(15, 115, 20, _imp_str_literal(""));
  }
  auto void Inc(int D);
  void Inc2(int D) {
    void Inc3(int D) {
      void Inc4(int D) {
        void Inc5(int D) {
          if (D > 400) {
            _imp_signal(15, 118, 0, _imp_str_literal(""));
            Printstring(_imp_str_literal("FAIL: To raise a deep event."));
            Newline();
            return;
          }
          Inc(D + 1);
        }
        Inc5(D + 1);
      }
      Inc4(D + 1);
    }
    Inc3(D + 1);
  }
  void Inc(int D) { Inc2(D + 1); }
  if (_imp_strcmp(Cliparam(), _imp_str_literal("")) == 0)
    Openoutput(1, _imp_str_literal("/tmp/EVENTS.out"));
  else {
    Printstring(_imp_join(_imp_str_literal("Writing to "), Cliparam()));
    Newline();
    Openoutput(1, Cliparam());
  }
  Selectoutput(1);
  Newlines(3);
  Printstring(_imp_str_literal("Test the Ability to Raise Standard Events"));
  Newline();
  Printstring(_imp_str_literal("-----------------------------------------"));
  Newlines(2);
  Teststandardevents();
  Newlines(2);
  Eventful(1);
Resume2:
  Eventful(0);
Resume3:
  Inc(1);
Resume4:;
  Printstring(_imp_str_literal("Returned from a depth correctly."));
  Newlines(2);
  Selectoutput(0);
  Write(Failures, 1);
  Printstring(_imp_str_literal(" failure(s)"));
  Newline();
  exit(0);
  return (1);
}
