#include <perms.h>

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

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

  //     2  %OWNINTEGER LABELNO=0

  static int LABELNO = 0;

  //     3  %CONSTINTEGER MAXLABELS=10
  //     4  %RECORDFORMAT F(%BYTE B,%STRING(255)LAB)

  struct F {
    union {
      struct {
        unsigned char B;
        _imp_string255 LAB;
      };
    };
  };

  //     5  %OWNSTRING(15)%ARRAY LBLNAME(0:MAXLABELS)

  static _imp_string15 LBLNAME[11];
  struct _imp_dv LBLNAME_dv = {LBLNAME, sizeof(_imp_string) /*, dims, <bounds> */};

  //     6  %OWNRECORD(F)%ARRAY LBL(0:MAXLABELS)

  static struct F LBL[11];
  struct _imp_dv LBL_dv = {LBL, sizeof(struct F) /*, dims, <bounds> */};

  //     7
  //     8  %RECORD(F)%MAP LABEL(%STRING(15) L)

  struct F *LABEL(_imp_string15 L) {
    //     9  %INTEGER I

    int I;

    //    10   %IF LABELNO>0 %THENSTART

    if (LABELNO <= 0) goto L_0001;

      //    11    %FOR I=1,1,LABELNO %CYCLE

    // %for I = 1, 1, LABELNO %cycle
    {
      int _final = LABELNO;
      if (invalid_for_loop(1, 1, _final)) _imp_signal(5, 1, 0, "Illegal cycle I = 1, 1, LABELNO");
      I = 0;
    L_0002:
      if (I == _final) goto L_0003;
      I += 1;

      //    12     %RESULT==LBL(I) %IF LBLNAME(I)=L


      /* clang-format off */
if (_imp_strcmp((_imp_string *)/*?*/&LBLNAME[I], (_imp_string *)/*?*/&L) != 0) goto L_0005;

      /* clang-format on */
      return /*?*/ &LBL[I];
    L_0005:;

    //    13    %REPEAT

      goto L_0002;
    }

  L_0003:;

  //    14   %FINISH

  L_0001:;

  //    15  !  INSERT NEW LABEL-NAME.
  //    16   LABELNO=LABELNO+1

    LABELNO = LABELNO + 1;

    //    17   %IF LABELNO>MAXLABELS %THENSTART

    if (LABELNO <= 10) goto L_0006;

      //    18    PRINT STRING(L." MAKES TOO MANY LABELS."); NEWLINE

    _imp_PRINTSTRING(
        /* clang-format off */
*({  __typeof__(_imp_string255) tmp = *({_imp_string255 tmp = _imp_join((_imp_string *)/*?*/&L, (_imp_string *)/*?*/_imp_str_literal_ptr(" MAKES TOO MANY LABELS.")); (_imp_string255 *)&tmp;})/*q*/;  (_imp_string255 *)&tmp;  })
        /* clang-format on */
    );
    _imp_NEWLINE();

    //    19    %FOR I=1,1,MAXLABELS %CYCLE

    // %for I = 1, 1, 10 %cycle
    {
      I = 0;
    L_0007:
      if (I == 10) goto L_0008;
      I += 1;

      //    20     PRINT STRING(LBLNAME(I))

      _imp_PRINTSTRING(
          /* clang-format off */
*({  __typeof__(_imp_string15) tmp = LBLNAME[I]/*q*/;  (_imp_string255 *)&tmp;  })
          /* clang-format on */
      );

      //    21     NEWLINE

      _imp_NEWLINE();

      //    22    %REPEAT

      goto L_0007;
    }

  L_0008:;

  //    23    %MONITOR

  /*_imp_monitor(__LINE__, __FILE__, PRETTY_FUNCTION);*/

  //    24    %STOP

    _imp_stop(0);

    //    25   %FINISH    ;!  DEALING WITH TOO MANY LABELS.

  L_0006:;

  //    26   LBLNAME(LABELNO)=L


    /* clang-format off */
_imp_strncpy(/*?*/&LBLNAME[LABELNO], ({__typeof__(_imp_string15) tmp;/*B*/ tmp = L; (void *)&tmp;}), /*max:*/15);

    /* clang-format on */

    //    27   LBL(LABELNO)_LAB=""


    /* clang-format off */
_imp_strncpy(/*?*/&LBL[LABELNO].LAB, ({__typeof__(_imp_string255) tmp;/*B*/ tmp = _imp_str_literal(""); (void *)&tmp;}), /*max:*/255);

    /* clang-format on */

    //    28   %RESULT==LBL(LABELNO)

    return /*?*/ &LBL[LABELNO];

    //    29  %END

  } /* end of LABEL */

  //    30
  //    31
  //    32
  //    33    LABEL("T")_LAB="TESTING USE OF LABEL"


  /* clang-format off */
_imp_strncpy(/*?*/&LABEL(_imp_str_literal_size(15, "T"))->LAB, ({__typeof__(_imp_string255) tmp;/*B*/ tmp = _imp_str_literal("TESTING USE OF LABEL"); (void *)&tmp;}), /*max:*/255);

  /* clang-format on */

  //    34    PRINT STRING(LABEL("T")_LAB); NEWLINE

  _imp_PRINTSTRING(
      /* clang-format off */
*({  __typeof__(_imp_string255) tmp = LABEL(_imp_str_literal_size(15, "T"))->LAB/*q*/;  (_imp_string255 *)&tmp;  })
      /* clang-format on */
  );
  _imp_NEWLINE();

  //    35    LABEL("T")_LAB="THIS SHOULD MODIFY ".LABEL("T")_LAB." AS I TRIED TO DO YESTERDAY"


  /* clang-format off */
_imp_strncpy(/*?*/&LABEL(_imp_str_literal_size(15, "T"))->LAB, ({__typeof__(_imp_string255) tmp;/*B*/ tmp = *({_imp_string255 tmp = _imp_join((_imp_string *)/*?*/&*({_imp_string255 tmp = _imp_join((_imp_string *)/*?*/_imp_str_literal_ptr("THIS SHOULD MODIFY "), (_imp_string *)/*?*/&LABEL(_imp_str_literal_size(15, "T"))->LAB); (_imp_string255 *)&tmp;}), (_imp_string *)/*?*/_imp_str_literal_ptr(" AS I TRIED TO DO YESTERDAY")); (_imp_string255 *)&tmp;}); (void *)&tmp;}), /*max:*/255);

  /* clang-format on */

  //    36    PRINT STRING(LABEL("T")_LAB); NEWLINE

  _imp_PRINTSTRING(
      /* clang-format off */
*({  __typeof__(_imp_string255) tmp = LABEL(_imp_str_literal_size(15, "T"))->LAB/*q*/;  (_imp_string255 *)&tmp;  })
      /* clang-format on */
  );
  _imp_NEWLINE();

  //    37  %ENDOFPROGRAM

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