#include <perms.h>

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

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

  //     2
  //     3  ! trying to duplicate crash from pass3.i
  //     4
  //     5  %constinteger max ref = 100
  //     6
  //     7  %recordformat  reffm(%shortinteger  tag, link, flags, ca)

  struct REFFM {
    union {
      struct {
        short int TAG;
        short int LINK;
        short int FLAGS;
        short int CA;
      };
    };
  };

  //     8  %recordformat  deffm(%record(deffm)%name  link, %shortinteger proc,ca)

  struct DEFFM {
    union {
      struct {
        struct DEFFM *LINK;
        short int PROC;
        short int CA;
      };
    };
  };

  //     9  %recordformat  procfm(%record(procfm)%name  link,

  struct PROCFM {
    union {
      struct {
        struct PROCFM *LINK;
        struct REFFM *REFLIST;
        struct DEFFM *DEFLIST;
        short int BASE;
        short int CA;
        short int STATICFRAME;
        short int EVENTMASK;
        short int DISPLAYREG;
        short int EVENTSTART;
        short int EVENTFINISH;
        short int LDBASE;
        short int LDSIZE;
        short int VDBASE;
        short int VDSIZE;
        short int ME;
      };
    };
  };

  //    10+                       %record(reffm)%name   ref list,
  //    11+                       %record(deffm)%name   def list,
  //    12+                       %shortinteger  base,  ca,
  //    13+                                      static frame, event mask,
  //    14+                                      display reg, event start,
  //    15+                                      event finish, ld base,
  //    16+                                      ld size, vd base,
  //    17+                                      vd size, Me)
  //    18
  //    19  %routine phase1

  void PHASE1(void) {
    //    20  %record(reffm)%array  ref(1:max ref)

    struct REFFM REF[100];
    struct _imp_dv REF_dv = {REF, sizeof(struct REFFM) /*, dims, <bounds> */};

    //    21  %record(procfm)%name  pp, qq

    struct PROCFM *PP;
    struct PROCFM *QQ;

    //    22    ref(1)_tag = 42

    REF[0].TAG = 42;

    //    23  %end

    return;
  } /* end of PHASE1 */

  // ?QQ unused
  // ?PP unused
  //    24
  //    25  %endofprogram

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