#include <perms.h>

//          Edinburgh IMP77 Compiler - Version 8.4
//
//     1  %BEGIN

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

  //     2
  //     3  !
  //     4  ! TEST A MAP USE THAT IS DIFFICULT TO OPTIMISE
  //     5  !
  //     6  %RECORDFORMAT F(%INTEGER I,J,K,%BYTEARRAY VOL(1:5),

  struct F {
    union {
      struct {
        int I;
        int J;
        int K;
        unsigned char VOL[5];
        unsigned char B;
        unsigned char LAB[3];
      };
    };
  };

  //     7+       %BYTE B,%BYTEARRAY LAB(1:3))
  //     8  %INTEGER I,J

  int I;
  int J;

  //     9  %RECORD(F) SP

  struct F SP;

  //    10  %RECORD(F)%NAME R

  struct F *R;

  //    11        R==SP

  R = (struct F *)/*?*/ &SP;

  //    12        R=0

  *R = (struct F){0};

  //    13        R_VOL(1)='A'

  R->VOL[0] = 65;

  //    14        R_VOL(2)='B'

  R->VOL[1] = 66;

  //    15        R_VOL(3)='C'

  R->VOL[2] = 67;

  //    16        R_VOL(4)='D'

  R->VOL[3] = 68;

  //    17        R_VOL(5)='E'

  R->VOL[4] = 69;

  //    18        %FOR I=1,1,5 %CYCLE

  // %for I = 1, 1, 5 %cycle
  {
    I = 0;
  L_0001:
    if (I == 5) goto L_0002;
    I += 1;

    //    19           BYTEINTEGER(ADDR(R_I)+1+I)=R_VOL(I)

    *_imp_BYTEINTEGER(_imp_ADDR(/*?*/ &R->I) + 1 + I) = R->VOL[I - 1];

    //    20        %REPEAT

    goto L_0001;
  }

L_0002:;

//    21        I=ADDR(R_VOL(5))

  I = _imp_ADDR(/*?*/ &R->VOL[4]);

  //    22        J=ADDR(R_LAB(1))

  J = _imp_ADDR(/*?*/ &R->LAB[0]);

  //    23        %IF R_I=M'AB' %AND R_J=M'CDE'<<8 %AND J-I=2 %THEN %c

  if (R->I != 16706) goto L_0004;
  if (R->J != 4408389 << 8) goto L_0004;
  if (J - I != 2) goto L_0004;
  _imp_PRINTSTRING(_imp_str_literal("TEST OK (Unswopped)"));
  _imp_stop(0);
L_0004:;

//    24+          PRINTSTRING("TEST OK (Unswopped)") %AND %STOP
//    25        %if R_I=M'BA'<<16 %and R_j=M'EDC' %and J-I=2 %then %C

  if (R->I != 16961 << 16) goto L_0005;
  if (R->J != 4539459) goto L_0005;
  if (J - I != 2) goto L_0005;
  _imp_PRINTSTRING(_imp_str_literal("TEST OK (Swopped)"));
  _imp_stop(0);
L_0005:;

//    26+          PRINTSTRING("TEST OK (Swopped)") %and %stop
//    27        WRITE(R_I,5)

  _imp_WRITE(R->I, 5);

  //    28        WRITE(R_J,5)

  _imp_WRITE(R->J, 5);

  //    29  %ENDOFPROGRAM

  _imp_stop(0);
  return 0;
end_0:;
}