#include <perms.h>
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  typedef struct Rfs {
    unsigned char B;
    short A;
    unsigned short Ha[2 /*1:2*/];
  } Rfs;
  typedef struct Rf {
    int I;
    Rf *R;
    int Ia[16 /*5:20*/];
    _imp_string S;
    char M;
    Rfs R2;
  } Rf;
  static const int Con = -6;
  _imp_string Param;
  static int Errors = 0;
  static int Failures = 0;
  int A;
  int B;
  int I;
  int J;
  int K;
  int L;
  int M;
  A = 49;
  B = 75;
  static int Aa[10 /*1:10*/] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int Ia1[31 /*-10:20*/];
  int Ia2[B - A + 1];
  int Ia3[6 /*95:100*/][4 /*-48:-45*/][(-A) - (-B) + 1][(B + 2) - (A + 20) + 1]
         [1 /*1:1*/][A - 45 + 1];
  int Ia4[10 /*1:10*/][3 /*3:5*/][3 /*6:8*/];
  int Ian1;
  int Ian4;
  int *In;
  static const unsigned char Cba[100 /*1:100*/] = {1,
                                                   2,
                                                   3,
                                                   4,
                                                   5,
                                                   6,
                                                   7,
                                                   8,
                                                   9,
                                                   10,
                                                   11,
                                                   12,
                                                   13,
                                                   14,
                                                   15,
                                                   16,
                                                   17,
                                                   18,
                                                   19,
                                                   [19 ... 28] = 20,
                                                   [29 ... 48] = 30,
                                                   [49 ... 99] = 50};
  static short Osa[10 /*-10:-1*/] = {-1, -2, -3, -4, -5,
                                     -6, -7, -8, -9, [9 ... 9] = -10};
  short Shan;
  char Ma1[11 /*-5:5*/];
  char Ma2[26 /*-5:20*/];
  char Man;
  static Rf Ora[11 /*20:30*/];
  Rf Ran1;
  Rf Ra2[(B - 5) - (A + 5) + 1][1 /*10:10*/][(-A) - (-B) + 1];
  Rf *Rn;
  Rfs *Rns;
  _imp_string Sa1[101 /*255:355*/];
  _imp_string Sa2[(B - 6) - (A + 6) + 1][11 /*9:19*/];
  _imp_string San1;
  static const _imp_string Csa[15 /*1:15*/] = {
      _imp_str_literal("MYMU"),   _imp_str_literal("POTA"),
      _imp_str_literal("NTDAG"),  _imp_str_literal("OOTN"),
      _imp_str_literal("MCNL"),   _imp_str_literal("LOMB"),
      _imp_str_literal("IYCSTH"), _imp_str_literal("RFYL"),
      _imp_str_literal("LT"),     _imp_str_literal("ROTG"),
      _imp_str_literal("TIYS"),   _imp_str_literal("GD"),
      _imp_str_literal("IHT"),    _imp_str_literal("YAYHSB"),
      _imp_str_literal("WWWY")};
  void Pass(void) {
    Printstring(_imp_str_literal("Pass"));
    Newline();
  }
  void Fail(void) {
    Printstring(_imp_str_literal("FAIL"));
    Newline();
    Failures++;
  }
  void Testconf(int Ianp, unsigned char A) {
    if (A == 1) {
      if (Low == -10 && High == 20)
        Pass();
      else
        Fail();
      Errors = 0;
      for (I = -10; I <= 20; I++)
        if (Ianp != I * I) Errors++;
      if (!Errors)
        Pass();
      else
        Fail();
    } else {
      if (Low == 49 && High == 75)
        Pass();
      else
        Fail();
      Errors = 0;
      for (I = High; I >= Low; I--)
        if (Ianp != I) Errors++;
      if (!Errors)
        Pass();
      else
        Fail();
      for (I = Low; I <= High; I++) Ianp = Ianp * 2;
    }
  }
  void Testconf2(int Ianp) {
    if (Low1 == 95 && High1 == 100 && Low2 == -48 && High2 == -45 &&
        Low3 == -75 && High3 == -49 && Low4 == 69 && High4 == 77 && Low5 == 1 &&
        High5 == 1 && Low6 == 45 && High6 == 49)
      Pass();
    else
      Fail();
    Errors = 0;
    for (I = 95; I <= 100; I++)
      for (J = -48; J <= -45; J++)
        for (K = -49; K >= -75; K--)
          for (L = A + 20; L <= B + 2; L++)
            for (M = 45; M <= 49; M++) {
              if (Ianp != I * J - K * L + M) Errors++;
              Ianp = I + J - K + L - 1 + M;
            }
    if (!Errors)
      Pass();
    else
      Fail();
  }
  void Checkarr(_imp_string Sap) {
    int A;
    Errors = 0;
    for (A = 255; A <= 355; A++)
      if (Sap != Csa[A - (A / 15) * 15 + 1]) Errors++;
    if (!Errors)
      Pass();
    else
      Fail();
  }
  void Testconf3(_imp_string Sap) {
    if (Low1 == 55 && High1 == 69 && Low2 == 9 && High2 == 19)
      Pass();
    else
      Fail();
    for (I = Low1; I <= High1; I++)
      for (J = Low2; J <= High2; J++) {
        Sap = _imp_str_literal("This is an array with first index ");
        Sap = _imp_join(Sap, _imp_join(Tostring(I / 10 + '0'),
                                       Tostring(I - (I / 10) * 10 + '0')));
      }
  }
  void Testconf4(Rf Rap) {
    if (Low1 == 54 && High1 == 70 && Low2 == 10 && High2 == 10 && Low3 == -75 &&
        High3 == -49)
      Pass();
    else
      Fail();
    Errors = 0;
    for (I = 54; I <= 70; I++)
      for (J = -75; J <= -49; J++) {
        if (Rap != I * 10 + J) Errors++;
        Rap++;
        if (Rap != I * 10 + J + 1) Errors++;
        for (K = 5; K <= 20; K++) {
          if (Rap != K * J * I) Errors++;
          Rap = K * J * I + 1;
        }
        if (Rap !=
            _imp_join(
                Tostring(K),
                _imp_join(Tostring(I),
                          _imp_join(Tostring(-J),
                                    _imp_str_literal(" some not printable")))))
          Errors++;
        Rap = _imp_join(Tostring(K * 5), Rap);
        if (Rap != I + J + K) Errors++;
        Rap = I + J + K + 1;
        if (Rap != I - J + K) Errors++;
        Rap = I - J + K + 1;
        if (Rap != I * 100 + J * 10 + K) Errors++;
        Rap = I * 100 + J * 10 + K + 1;
        if (Rap != I * 100 - J * 10 + K) Errors++;
        Rap = I * 100 - J * 10 + K + 1;
        if (Rap != K * 31 - J * 75 + K * 37) Errors++;
        Rap = K * 31 - J * 75 + K * 37 + 1;
      }
    if (!Errors)
      Pass();
    else
      Fail();
  }
  int Sigma(int A) {
    int I;
    int J = 0;
    for (I = 1; I <= 10; I++) J += A;
    return (J);
  }
  int Sigma2(int A) {
    int I;
    int J = 0;
    for (I = 1; I <= 10; I++) J = J + J + A;
    return (J);
  }
  int Sigma3(int A) {
    int I;
    int J = 0;
    for (I = 1; I <= 10; I++) J = J + J + J + A;
    return (J);
  }
  int Change(int A) {
    int I;
    int J = 0;
    for (I = 1; I <= 10; I++) A = A * 2;
    for (I = 3; I <= 9; I++) J += A;
    return (J);
  }
  int Check(int A) {
    int I;
    int J = 0;
    for (I = 1; I <= 10; I++)
      if (A == I * 2) J++;
    return (J);
  }
  void Do(void F(int X), int Res) {
    int I;
    void Pass(void) {
      Printstring(_imp_str_literal("Pass"));
      Newline();
    }
    void Fail(void) {
      Printstring(_imp_str_literal("FAIL :"));
      Printstring(_imp_str_literal(" Was expecting"));
      Write(Res, 1);
      Printstring(_imp_str_literal(" and got"));
      Write(I, 1);
      Newline();
      Failures++;
    }
    I = F;
    if (I == Res)
      Pass();
    else
      Fail();
  }
  Param = Cliparam();
  if (Param == _imp_str_literal(""))
    Selectoutput(2);
  else if (Param == _imp_str_literal("s") || Param == _imp_str_literal("S"))
    Selectoutput(0);
  else if (Param == _imp_str_literal("j") || Param == _imp_str_literal("J")) {
    Openoutput(2, _imp_str_literal("journal"));
    Selectoutput(2);
  } else {
    Openoutput(2, Param);
    Selectoutput(2);
  }
  Newline();
  Printstring(_imp_str_literal("Tests on Arrays and Array Names"));
  Newline();
  Printstring(_imp_str_literal("==============================="));
  Newlines(3);
  Printstring(_imp_str_literal("Integer array names as parameters"));
  Newline();
  Printstring(_imp_str_literal("---------------------------------"));
  Newline();
  Do(Sigma(), 55);
  Do(Sigma2(), 2036);
  Do(Sigma3(), 44281);
  Do(Change(), 84);
  Do(Check(), 10);
  Newlines(2);
  Printstring(_imp_str_literal(
      "Testing Integer Arrays with Constant Bounds, 1 Dimension"));
  Newline();
  Printstring(_imp_str_literal(
      "--------------------------------------------------------"));
  Newline();
  for (I = 20; I >= -10; I--) Ia1[I] = IEXP(I, 2);
  *Ian1 = &Ia1;
  Errors = 0;
  for (I = 20; I >= -10; I--)
    if (Ia1[I] != IEXP(I, 2)) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  Errors = 0;
  for (I = -10; I <= 20; I++)
    if (Ian1(I) != I * I) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  In = Ian1;
  if (*In == 400)
    Pass();
  else
    Fail();
  In = &Ia1[-1];
  if (*In == 1)
    Pass();
  else
    Fail();
  Testconf(Ia1, 1);
  Testconf(Ian1, 1);
  J = 0;
  for (I = 1; I <= 100; I++) J += Cba[I];
  if (J == 3540)
    Pass();
  else
    Fail();
  *Shan = &Osa;
  for (I = -1; I >= -10; I--) Shan(I) = Ian1(I);
  Errors = 0;
  for (I = 1; I <= 10; I++)
    if (Osa[-I] != IEXP(I, 2)) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  for (I = -5; I <= 20; I++) Ma2[I] = I * 8 - 80;
  *Man = &Ma2;
  Errors = 0;
  for (I = -5; I <= 20; I++)
    if (Man(I) != (I - 10) * 8) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  *Man = &Ma1;
  for (I = -5; I <= 5; I++) Man(I) = Ma2[I] / 2;
  Errors = 0;
  for (I = -5; I <= 5; I++)
    if (Ma1[I] != Ma2[I] / 2) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  *Man = &Ma2;
  Errors = 0;
  for (I = -5; I <= 20; I++)
    if (Man(I) != -80 + 8 * I) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  Printstring(_imp_str_literal("3 dimensional, constant bounds"));
  Newline();
  Errors = 0;
  for (I = 1; I <= 10; I++)
    for (J = 3; J <= 5; J++)
      for (K = 6; K <= 8; K++) Ia4[I][J][K] = I * J * K;
  if (!Errors)
    Pass();
  else
    Fail();
  *Ian4 = &Ia4;
  Errors = 0;
  for (I = 1; I <= 10; I++)
    for (J = 3; J <= 5; J++)
      for (K = 6; K <= 8; K++) {
        if (Ian4(I, J, K) != K * J * I) Errors++;
        Ian4(I, J, K) = I + J + K;
      }
  if (!Errors)
    Pass();
  else
    Fail();
  Errors = 0;
  for (J = 6; J <= 8; J++)
    for (K = 1; K <= 10; K++)
      for (I = 3; I <= 5; I++)
        if (Ia4[K][I][J] != I + J + K) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  Printstring(_imp_str_literal("6 dimensional, variable bounds -"));
  for (I = 95; I <= 100; I++)
    for (J = -48; J <= -45; J++)
      for (K = -B; K <= -A; K++)
        for (L = 69; L <= 77; L++)
          for (M = 45; M <= A; M++) Ia3[I][J][K][L][1][M] = I * J - K * L + M;
  Printstring(_imp_str_literal("  initialised"));
  Newline();
  Testconf2(Ia3);
  Printstring(_imp_str_literal(" final pass"));
  Newline();
  Errors = 0;
  for (I = 95; I <= 100; I++)
    for (J = -48; J <= -45; J++)
      for (K = -75; K <= -49; K++)
        for (L = 69; L <= 77; L++)
          for (M = 45; M <= 49; M++)
            if (Ia3[I][J][K][L][1][M] != I + J - K + L - 1 + M) Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  In = &Ia3[96][-47][-49][70][1][46];
  if (*In == 96 - 47 + 49 + 70 - 1 + 46)
    Pass();
  else
    Fail();
  *In = 317537;
  if (Ia3[96][-47][-49][70][1][46] == 317537)
    Pass();
  else
    Fail();
  Newlines(2);
  Printstring(_imp_str_literal("Checking String Arrays"));
  Newline();
  Printstring(_imp_str_literal("----------------------"));
  Newline();
  if (Csa[1] == _imp_str_literal("MYMU") &&
      Csa[2] == _imp_str_literal("POTA") &&
      Csa[3] == _imp_str_literal("NTDAG") &&
      Csa[4] == _imp_str_literal("OOTN") &&
      Csa[5] == _imp_str_literal("MCNL") &&
      Csa[6] == _imp_str_literal("LOMB") &&
      Csa[7] == _imp_str_literal("IYCSTH") &&
      Csa[8] == _imp_str_literal("RFYL") && Csa[9] == _imp_str_literal("LT") &&
      Csa[10] == _imp_str_literal("ROTG") &&
      Csa[11] == _imp_str_literal("TIYS") &&
      Csa[12] == _imp_str_literal("GD") && Csa[13] == _imp_str_literal("IHT") &&
      Csa[14] == _imp_str_literal("YAYHSB") &&
      Csa[15] == _imp_str_literal("WWWY"))
    Pass();
  else
    Fail();
  for (I = 255; I <= 355; I++)
    Sa1[I] =
        _imp_join(_imp_str_literal("This is element no "), Tostring(I - 255));
  Errors = 0;
  for (I = 255; I <= 355; I++)
    if (Sa1[I] !=
        _imp_join(_imp_str_literal("This is element no "), Tostring(I - 255)))
      Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  *San1 = &Sa1;
  Errors = 0;
  for (I = 255; I <= 355; I++) {
    if (San1(I) !=
        _imp_join(_imp_str_literal("This is element no "), Tostring(I - 255)))
      Errors++;
    San1(I) = Csa[I - (I / 15) * 15 + 1];
  }
  if (!Errors)
    Pass();
  else
    Fail();
  Checkarr(Sa1);
  Testconf3(Sa2);
  Errors = 0;
  for (I = 9; I <= 19; I++)
    for (J = 55; J <= 69; J++) {
      if (Sa2[J][I] !=
          _imp_join(_imp_str_literal("This is an array with first index "),
                    _imp_join(Tostring(J / 10 + '0'),
                              Tostring(J - (J / 10) * 10 + '0'))))
        Errors++;
      Sa2[J][I] = _imp_join(
          Sa2[J][I], _imp_join(_imp_str_literal(" and second "),
                               _imp_join(Tostring(I / 10 + '0'),
                                         Tostring(I - (I / 10) * 10 + '0'))));
    }
  if (!Errors)
    Pass();
  else
    Fail();
  Errors = 0;
  for (I = 9; I <= 19; I++)
    for (J = 55; J <= 69; J++)
      if ((*Charno(Sa2[J][I], 49) - '0') * 10 + *Charno(Sa2[J][I], 50) - '0' !=
          I)
        Errors++;
  if (!Errors)
    Pass();
  else
    Fail();
  Newlines(2);
  Printstring(_imp_str_literal("Testing Record Arrays and names"));
  Newline();
  Printstring(_imp_str_literal("-------------------------------"));
  Newline();
  for (I = 20; I <= 30; I++) {
    Ora[I].I = I * 10;
    Ora[I].R = &Ora[I];
    for (J = 5; J <= 20; J++) Ora[I].Ia = I * J;
    Ora[I].S = Csa[I - 16];
    Ora[I].M = I + 50;
    Ora[I].R2 = I + 200;
    Ora[I].R2 = -I * 500;
    Ora[I].R2 = I / 3 * 200;
    Ora[I].R2 = -Ora[I].R2;
  }
  Errors = 0;
  for (I = 20; I <= 30; I++) {
    Rn = &Ora[I];
    if (Rn->I != I * 10) Errors++;
    if (Rn->R != I * 10) Errors++;
    for (J = 5; J <= 20; J++)
      if (Rn->Ia != J * I) Errors++;
    if (Rn->S != Csa[I - 16]) Errors++;
    if (Ora[I].M != I + 50) Errors++;
    Rns = &Rn->R2;
    if (Rns->B != I + 200) Errors++;
    if (Rns->A != -I * 500) Errors++;
    if (Ora[I].R2 != I / 3 * 200) Errors++;
    if (Rn->R2 != -Rns->A) Errors++;
  }
  if (!Errors)
    Pass();
  else
    Fail();
  *Ran1 = &Ora;
  Errors = 0;
  for (I = 20; I <= 30; I++) {
    Rn = Ran1;
    if (Ran1(I).I != I * 10) Errors++;
    if (Rn->R != I * 10) Errors++;
    for (J = 5; J <= 20; J++)
      if (Ran1(I).Ia != I * J) Errors++;
    if (Rn->S != Csa[I - 16]) Errors++;
    if (Rn->M != I + 50) Errors++;
    Rns = &Ran1(I).R2;
    if (Ran1(I).R2 != I + 200) Errors++;
    if (Rns->A != -I * 500) Errors++;
    if (Rn->R2 != I / 3 * 200) Errors++;
    if (Rns->Ha != -Rns->A) Errors++;
  }
  if (!Errors)
    Pass();
  else
    Fail();
  for (I = 54; I <= 70; I++)
    for (J = -75; J <= -49; J++) {
      Ra2[I][10][J].I = I * 10 + J;
      Rn = &Ra2[I][10][J];
      Rn->R = Rn;
      for (K = 5; K <= 20; K++) Rn->Ia = K * J * I;
      Rn->S = _imp_join(
          Tostring(K),
          _imp_join(Tostring(I),
                    _imp_join(Tostring(-J),
                              _imp_str_literal(" some not printable"))));
      Ra2[I][10][J].M = I + J + K;
      Rns = &Rn->R2;
      Rns->B = I - J + K;
      Ra2[I][10][J].R2 = I * 100 + J * 10 + K;
      Rns->Ha = I * 100 - J * 10 + K;
      Rns->Ha = K * 31 - J * 75 + K * 37;
    }
  Testconf4(Ra2);
  Errors = 0;
  for (I = 54; I <= 70; I++)
    for (J = -75; J <= -49; J++) {
      Rn = &Ra2[I][10][J];
      Rns = &Rn->R2;
      if (Rn->I != I * 10 + J + 1) Errors++;
      if (Rn->R != I + J + K + 1) Errors++;
      for (K = 5; K <= 20; K++)
        if (Rn->Ia != K * J * I + 1) Errors++;
      if (Rn->S !=
          _imp_join(
              Tostring(5 * K),
              _imp_join(Tostring(K),
                        _imp_join(Tostring(I),
                                  _imp_join(Tostring(-J),
                                            _imp_str_literal(
                                                " some not printable"))))))
        Errors++;
      if (Rn->M != I + J + K + 1) Errors++;
      if (Rns->B != I - J + K + 1) Errors++;
      if (Rns->A != I * 100 + J * 10 + K + 1) Errors++;
      if (Rns->Ha != I * 100 - J * 10 + K + 1) Errors++;
      if (Rns->Ha != K * 31 - J * 75 + K * 37 + 1) Errors++;
    }
  if (!Errors)
    Pass();
  else
    Fail();
  Selectoutput(0);
  Write(Failures, 1);
  Printstring(_imp_str_literal(" failure(s)"));
  Newline();
  exit(0);
  return (1);
}
