#include <perms.h>

//          Edinburgh IMP77 Compiler - Version 8.4
//
//     1  !
//     2  ! pass1 doesn't pass the recordformatspec through, and although we can detect when
//     3  ! 'recfm' is used before it has been fully specified, we can't know the original
//     4  ! location where it was declared.  We have to take care when reinserting a generated
//     5  ! recordformatspec to place it where it applies to all necessary uses.
//     6  !
//     7  %begin

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

  //     8    %recordformatspec recfm                  { recordformat spec has to be inserted here    }
  //     9    %integer i = 42                          { or here.  NOT in nest1 because then it would }

  int I;
  I = 42;

  //    10    %integermap nest1                        { already be out of scope again before the     }

  int *NEST1(void) {
    //    11      %integer filler = 17                   { decaration of 'another'                      }

    int FILLER;
    FILLER = 17;

    //    12      %ownrecord (recfm) %name fred

    static struct RECFM *FRED;

    //    13      %result == INTEGER(ADDR(fred))

    return _imp_INTEGER(_imp_ADDR(FRED));

    //    14    %end

  } /* end of NEST1 */

  // ?FILLER unused
  //    15    %record (recfm) %name another

  struct RECFM *ANOTHER;

  //    16    %recordformat recfm(%integer q)

  struct RECFM {
    union {
      struct {
        int Q;
      };
    };
  };

  //    17    nest1 = 42

  *NEST1() = 42;

  //    18    write(nest1, 0)

  _imp_WRITE(*NEST1(), 0);

  //    19    newline

  _imp_NEWLINE();

  //    20  %endofprogram

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