#include <perms.h>

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

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

  //     2
  //     3    ! %prim     %byte %integer  %map  %spec   charno( %string(255) s,%integer n )
  //     4
  //     5    %byteintegermap my charno(%string(255) s, %integer n)

  unsigned char *MYCHARNO(_imp_string255 S, int N) {
    //     6      %result == BYTEINTEGER(ADDR(s)+n)

    return _imp_BYTEINTEGER(_imp_ADDR(/*?*/ &S) + N);

    //     7    %end

  } /* end of MYCHARNO */

  //     8
  //     9    %string(255) string = "00"

  _imp_string255 STRING;

  /* clang-format off */
_imp_strncpy(/*?*/&STRING, ({__typeof__(_imp_string255) tmp;/*B*/ tmp = _imp_str_literal("00"); (void *)&tmp;}), /*max:*/255);

  /* clang-format on */

  //    10
  //    11    my charno(string,1) = '1'   ;! <-- does not affect string

  *MYCHARNO(
      /* clang-format off */
*({  __typeof__(_imp_string255) tmp = STRING/*q*/;  (_imp_string255 *)&tmp;  })
      /* clang-format on */
      ,
      1) = 49;

  //    12    charno(string, 2) = '2'     ;! <-- *does* modify string even though the prim

  *_imp_CHARNO((_imp_string255 *)/*p*/ /*?*/ &STRING, 2) = 50;

  //    13                                 !     declaration is the same as my local one.
  //    14
  //    15    printstring(string); newline  ;! This outputs: 02

  _imp_PRINTSTRING(
      /* clang-format off */
*({  __typeof__(_imp_string255) tmp = STRING/*q*/;  (_imp_string255 *)&tmp;  })
      /* clang-format on */
  );
  _imp_NEWLINE();

  //    16
  //    17  %endofprogram

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