#include <perms.h>
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  _imp_enter();
  const int LOW = 0;
  const int HIGH = 25 * 10 + 5;
  const char CB[265 - 10 + 1] = {5, 10, 20, 30, 40, 50};
  _imp_string S[12010 - 12000 + 1];
  int J[3 - 1 + 1][1 - -1 + 1][1023 - 0 + 1][0 - -1 + 1];
  char B[HIGH - LOW + 1];
  _imp_string T;
  int K;
  int L;
  int M;
  int N;
  int ACC;
  char BYTE;
  int ERRORS = 0;

  typedef struct RA {
    int A;

  } RA;

  typedef struct RB {
    int C;
    int B[10 - 0 + 1];
    int A;

  } RB;

  typedef struct RC {
    int C[10 - 1 + 1];
    RB B[3 - 0 + 1];
    RC *NEXT;

  } RC;

  typedef struct RD {
    int A;

  } RD;
  RA RECA;
  RB RECB[13 - 10 + 1];
  RC RECC[3 - 1 + 1];
  RD RECD;
  int *PINT1;
  int *PINT2;
  _imp_string *PSTR;
  RC *PRC;
  RC *PRC2;
  RC *PRCA;
  int *PINTA;
  static int FAILURES = 0;
  auto void PASS(void) {
    _imp_enter();
    PRINTSTRING(_imp_str_literal("Pass: "));
    _imp_leave();
  }
  auto void FAIL(void) {
    _imp_enter();
    PRINTSTRING(_imp_str_literal("FAIL: "));
    FAILURES = FAILURES + 1;
    _imp_leave();
  }
  OPENOUTPUT(2, _imp_str_literal("Journal"));
  SELECTOUTPUT(2);
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("%RECORD, %ARRAY and %NAME Validation"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("===================================="));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("Entities:"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("-------- "));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("Constants:                      "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("---------                       "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer  Low   = 0             "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer  High  = 25 * 10 + 5   "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Byte %Integer %Array  Bits2 =  "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("5(0), 10(10), 20(20), 30(30), 40(40), 50(*)"));
  NEWLINES(3);
  PRINTSTRING(_imp_str_literal("Record Formats                  "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("--------------                  "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("RA (%Integer A)                 "));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("RB (%Integer A,                 "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("    %Integer %Array B (0 : 10), "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("    %Integer C)                 "));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("RC (%Record (RC) %Name  Next,   "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("    %Record (RB) %Array B (0:3),"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("    %Integer %Array C (1:10))   "));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("RD (%Integer A  %orc            "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("    %Byte %Array B (0:10)       "));
  NEWLINES(3);
  PRINTSTRING(_imp_str_literal("Variables: "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("---------  "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer K "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer L "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer M "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer N "));
  NEWLINES(2);
  PRINTSTRING(
      _imp_str_literal("%Integer %Array        J (1:3, -1:1, 0:1023, -1:0)"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%String(255) %Array    S (12000 : 12010)"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Byte %Integer %Array  B (Low : High)"));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("%Record (RA)         Rec A"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Record (RB) %Array  Rec B (10 : 13)"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Record (RC) %Array  Rec C (1 : 3)"));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("%Record (RD)         Rec D"));
  NEWLINE();
  NEWLINES(3);
  PRINTSTRING(_imp_str_literal("%Name Variables                 "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("---------------                 "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer      %Name PInt1, PInt2"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%String(255)  %Name PStr        "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Record (RC) %Name  PRC, PRC2   "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Record (RC) %Array %Name  PRCA "));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("%Integer     %Array %Name  PIntA"));
  NEWLINE();
  NEWLINES(5);
  NEWLINES(3);
  PRINTSTRING(_imp_str_literal("Check the SIZE OF Function for Structures."));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("------------------------------------------"));
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("SIZE OF (S) ="));
  WRITE(SIZEOF(S), 1);
  if (SIZEOF(S) == 2816)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (J) ="));
  WRITE(SIZEOF(J), 1);
  if (SIZEOF(J) == 73728)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (B) ="));
  WRITE(SIZEOF(B), 1);
  if (SIZEOF(B) == 256)
    PASS();
  else
    FAIL();
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("SIZE OF (Rec A) ="));
  WRITE(SIZEOF(RECA), 1);
  if (SIZEOF(RECA) == 4)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (Rec B) ="));
  WRITE(SIZEOF(RECB), 1);
  if (SIZEOF(RECB) == 208)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (Rec C) ="));
  WRITE(SIZEOF(RECC), 1);
  if (SIZEOF(RECC) == 756)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (Rec D) ="));
  WRITE(SIZEOF(RECD), 1);
  if (SIZEOF(RECD) == 12)
    PASS();
  else
    FAIL();
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("SIZE OF (PInt1) ="));
  WRITE(SIZEOF(PINT1), 1);
  if (SIZEOF(PINT1) == 4)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (PStr) ="));
  WRITE(SIZEOF(PSTR), 1);
  if (SIZEOF(PSTR) == 256)
    PASS();
  else
    FAIL();
  NEWLINE();
  PRINTSTRING(_imp_str_literal("SIZE OF (PRCA) ="));
  WRITE(SIZEOF(PRCA), 1);
  if (SIZEOF(PRCA) == 756)
    PASS();
  else
    FAIL();
  NEWLINE();
  NEWLINES(3);
  PRINTSTRING(_imp_str_literal("Check Assignment to Structured Elements"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("---------------------------------------"));
  NEWLINES(2);
  for (K = 12000; K != 12010 + 1; K += 1) S[K] = TOSTRING('A' + K - 12000);
  for (K = 0; K != 255 + 1; K += 1) B[K] = CB[265 - K];
  ACC = 0;
  for (K = 1; K != 3 + 1; K += 1) {
    for (L = -1; L != 1 + 1; L += 1) {
      for (M = 0; M != 1023 + 1; M += 1) {
        for (N = -1; N != 0 + 1; N += 1) {
          ACC = ACC + 1;
          J[K][L][M][N] = ACC;
        }
      }
    }
  }
  RECA.A = 4;
  if (RECA.A == 4)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Rec A_A = 4"));
  NEWLINE();
  K = J[2][0][500][0];
  if (J[1][-1][0][-1] == 1 && J[3][1][1023][0] == 18432 && K == 9194)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("%INTEGER %ARRAY assignment and access."));
  NEWLINE();
  for (K = 0; K != 255 + 1; K += 1) {
    WRITE(K, 1);
    PRINTSYMBOL(':');
    WRITE(B[K], 0);
    if ((K & 7) == 0)
      NEWLINE();
    else
      SPACES(2);
  }
  NEWLINE();
  if (B[0] == 50 && B[180] == 40 && B[240] == 20 && B[255] == 10)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("%BYTE %INTEGER %ARRAY assignment and access."));
  NEWLINE();
  B[0] = 1;
  B[1] = 2;
  B[2] = 3;
  B[3] = 4;
  B[4] = 5;
  B[5] = 200;
  L = B[B[B[B[B[B[0]]]]]];
  if (L == 200)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Accessing element:  B(B(B(B(B(B(0))))))"));
  NEWLINE();
  T = _imp_join(
      S[12000],
      _imp_join(S[12001],
                _imp_join(S[12002],
                          _imp_join(S[12003], _imp_join(S[12004], S[12005])))));
  T = _imp_join(
      T,
      _imp_join(S[12006],
                _imp_join(S[12007],
                          _imp_join(S[12008], _imp_join(S[12009], S[12010])))));
  if (T == _imp_str_literal("ABCDEFGHIJK"))
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("%STRING %ARRAY assignment and access."));
  NEWLINES(2);
  for (L = 10; L != 13 + 1; L += 1) {
    RECB[L].A = RECA.A + 1;
    for (K = 0; K != 10 + 1; K += 1) RECB[L].B[K] = K;
    RECB[L].C = 0;
    for (K = 0; K != 10 + 1; K += 1) RECB[L].C = RECB[L].C + RECB[L].B[K];
    RECB[L].C = RECB[L].C + L;
  }
  ERRORS = 0;
  for (K = 10; K != 13 + 1; K += 1) {
    if (RECB[K].C != K + 55) ERRORS = ERRORS + 1;
  }
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Assignment and accessing REC A and REC B"));
  NEWLINE();
  for (K = 1; K != 3 + 1; K += 1) {
    if (K == 3)
      L = 1;
    else
      L = K + 1;
    RECC[K].NEXT = &RECC[L];
    for (L = 1; L != 10 + 1; L += 1) RECC[K].C = (K - 1) * 10 + L;
    RECC[K].B[1] = 0;
    RECC[K].B[2] = RECB[10 + K];
    RECC[K].B[2].A = K;
    RECC[K].B[3].A = 10 * K;
    for (L = 0; L != 10 + 1; L += 1) RECC[K].B[3].B[L] = L;
    RECC[K].B[3].C = -K;
  }
  if (RECC[1].C == 5 && RECC[2].C == 16 && RECC[3].C == 27)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Assignment to REC C(?)_C array."));
  NEWLINE();
  ERRORS = 0;
  for (K = 1; K != 3 + 1; K += 1) {
    if (RECC[K].B[1].A != 0 || RECC[K].B[1].C != 0) ERRORS = ERRORS + 1;
  }
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Simple assignment to Rec C(?)_B(1)_A and _C"));
  NEWLINE();
  ERRORS = 0;
  for (K = 1; K != 3 + 1; K += 1) {
    ACC = 0;
    for (L = 0; L != 10 + 1; L += 1) ACC = ACC + RECC[K].B[1].B[L];
    if (ACC != 0) ERRORS = ERRORS + 1;
  }
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Array assignment to Rec C(?)_B(1)_B(?)"));
  NEWLINE();
  ERRORS = 0;
  for (K = 1; K != 3 + 1; K += 1) {
    if (RECC[K].B[2].A != K || RECC[K].B[3].A != K * 10 ||
        RECC[K].B[2].C != 55 + K + 10 || RECC[K].B[3].C != -K)
      ERRORS = ERRORS + 1;
  }
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Simple assignment to Rec C(?)_B(2)_A and _C"));
  NEWLINE();
  ERRORS = 0;
  for (K = 1; K != 3 + 1; K += 1) {
    ACC = 0;
    for (L = 0; L != 10 + 1; L += 1) ACC = ACC + RECC[K].B[3].B[L];
    if (ACC != 55) ERRORS = ERRORS + 1;
  }
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Array assignment to Rec C(?)_B(3)_B(?)"));
  NEWLINE();
  RECD = 0;
  if (RECD.A == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Rec D = 0"));
  NEWLINE();
  for (K = 0; K != 10 + 1; K += 1) RECD.B[K] = CHARNO(T, K + 1);
  T = _imp_str_literal("");
  for (K = 0; K != 10 + 1; K += 1) T = _imp_join(T, TOSTRING(RECD.B[K]));
  if (T == _imp_str_literal("ABCDEFGHIJK"))
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Simple assignment to Rec D_B(?)"));
  NEWLINE();
  RECD.A = -256;
  if (RECD.A == -256 && RECD.B[4] == 'E')
    PASS();
  else
    FAIL();
  PRINTSTRING(
      _imp_str_literal("Assignment to alternative fields within Rec D"));
  NEWLINES(2);
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("Test the Pointer Variables"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("--------------------------"));
  NEWLINES(2);
  K = 2;
  L = 3;
  PINT1 = &K;
  PINT2 = &L;
  if (PINT1 == 2 && PINT2 == 3)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Reference to integer variable."));
  NEWLINE();
  ERRORS = 0;
  *PINT1 = 4;
  if (K != 4) ERRORS = ERRORS + 1;
  K = 5;
  if (PINT1 != 5) ERRORS = ERRORS + 1;
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(
      _imp_str_literal("Accessing %Integer directly and by reference."));
  NEWLINE();
  ERRORS = 0;
  if (PINT1 == PINT2) ERRORS = ERRORS + 1;
  if (PINT1 == PINT2) ERRORS = ERRORS + 1;
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Comparison of reference variables."));
  NEWLINE();
  *PINT1 = PINT2;
  if (K == 3 && PINT1 != PINT2)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PInt1 = PInt2  does not affect reference."));
  NEWLINE();
  PINT1 = PINT2;
  if (K == 3 && PINT1 == PINT2)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PInt1 == PInt2  does affect reference."));
  NEWLINE();
  if (K == 3 && L == 3)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Simple variables unaffected by dereference."));
  NEWLINE();
  ERRORS = 0;
  PSTR = &T;
  if (PSTR != _imp_str_literal("ABCDEFGHIJK")) ERRORS = ERRORS + 1;
  *PSTR = _imp_str_literal("New");
  if (T != _imp_str_literal("New")) ERRORS = ERRORS + 1;
  if (ERRORS == 0)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Reference to a String variable."));
  NEWLINES(2);
  PRCA = &RECC;
  PRC = &RECC[3];
  if (PRCA.NEXT == PRC)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Record Array reference and access."));
  NEWLINE();
  PINTA = &PRCA.C;
  ACC = 0;
  for (L = 1; L != 10 + 1; L += 1) ACC = ACC + PINTA;
  if (ACC == 255)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal(
      "Integer array reference via a Record Array reference."));
  NEWLINES(2);
  PRC = &RECC[1];
  PRC2 = &RECC[2];
  if (PRC != PRC2)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PRC ## PRC2"));
  NEWLINE();
  if (PRC != PRC2)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PRC == PRC2"));
  NEWLINE();
  if (PRC->NEXT->NEXT->NEXT == PRC)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PRC_Next_Next_Next == PRC"));
  NEWLINE(); /*ERROR: name_sym_idx is -1!*/ /*C_NAME*/
  PRC = &; /*ERROR: name_sym_idx is -1!*/   /*C_NAME*/
      /*ERROR: name_sym_idx is -1!*/        /*C_NAME*/
  if (PRC == () && PRC != PRC2 && () == PRC)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PRC == Nil  does affect reference."));
  NEWLINE(); /*ERROR: name_sym_idx is -1!*/ /*C_NAME*/
  PRC2 = &;
  if (PRC == PRC2)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PRC == PRC2  comparison for NIL."));
  NEWLINES(2);
  NEWLINES(2);
  PRINTSTRING(
      _imp_str_literal("Test the Address Modification of %Name Variables"));
  NEWLINE();
  PRINTSTRING(
      _imp_str_literal("------------------------------------------------"));
  NEWLINES(2);
  PINT1 = PINTA;
  if (PINT1 == 25 && PINT1 == 23 && PINT1 == 30)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Integer Array Address modification."));
  NEWLINE();
  PRC = &RECC[2];
  if (PRC->C == 11 && PRC->C == 1 && PRC->C == 21)
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("Record Array Address modification."));
  NEWLINES(2);
  NEWLINES(2);
  PRINTSTRING(_imp_str_literal("Test the ADDR Function and Access Maps"));
  NEWLINE();
  PRINTSTRING(_imp_str_literal("--------------------------------------"));
  NEWLINES(2);
  PINT1 = &K;
  if (PINT1 == INTEGER(ADDR(K)))
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PInt1 == INTEGER (ADDR (K))"));
  NEWLINE();
  PSTR = &T;
  if (PSTR == STRING(ADDR(T)))
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PSTR == STRING (ADDR (T))"));
  NEWLINE();
  PRC = &RECC[2];
  if (PRC == RECORD(ADDR(RECC[2])))
    PASS();
  else
    FAIL();
  PRINTSTRING(_imp_str_literal("PRC == RECORD (ADDR (Rec C(2))"));
  NEWLINE();
  SELECTOUTPUT(0);
  WRITE(FAILURES, 1);
  PRINTSTRING(_imp_str_literal(" failure(s)"));
  NEWLINE();
  _imp_leave();
  exit(0);
  return (0);
}
