#include <perms.h>

//          Edinburgh IMP77 Compiler - Version 8.4
//
//     1
//     2
//     3  %externalintegerfn get YNX

int GETYNX(void) {
  //     4    %on %event 9 %start

  if (!_imp_on_event(9)) goto L_0001;

    //     5      %result = 'X'

  return 88;

  //     6    %finish

L_0001:;

//     7    %integer c

  int C;

  //     8    %cycle

L_0002:;

//     9      !read symbol(c)  ;! read symbol currently not working due to %name parameters not being handled yet.
//    10      c = next symbol; skip symbol

  C = _imp_NEXTSYMBOL();
  _imp_SKIPSYMBOL();

  //    11      %signal 7,1,0 %if c = '?'

  if (C != 63) goto L_0003;
  _imp_signal(7, 1, 0, "");
L_0003:;

//    12      c = c - 'a' + 'A' %if 'a' <= c <= 'z'

  {
// Double-sided test on C (Part I)
    int tmp;
    if (97 > (tmp = C)) goto L_0004;
// Double-sided test on C (Part II)
    if (tmp > 122) goto L_0004;
  }
  C = C - 97 + 65;
L_0004:;

//    13      %result = c %if c = 'Y' %or c = 'N'

  if (C == 89) goto L_0005;
  if (C != 78) goto L_0006;
L_0005:;
  return C;
L_0006:;

//    14    %repeat

  goto L_0002;

  //    15  %end

} /* end of GETYNX */

//    16
//    17  ! A complete program.  Should run.
//    18  %begin

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

  //    19    %integer Answer

  int ANSWER;

  //    20    %on %event 7 %start

  if (!_imp_on_event(7)) goto L_0007;

    //    21      print string("What indeed?"); newline

  _imp_PRINTSTRING(_imp_str_literal("What indeed?"));
  _imp_NEWLINE();

  //    22      ! drop through and restart...
  //    23    %finish

L_0007:;

//    24
//    25    prompt("Y or N: ");

  _imp_PROMPT(_imp_str_literal_size(15, "Y or N: "));

  //    26    print string("Starting"); newline

  _imp_PRINTSTRING(_imp_str_literal("Starting"));
  _imp_NEWLINE();

  //    27    %cycle

L_0008:;

//    28      Answer = get YNX

  ANSWER = GETYNX();

  //    29      %if Answer = 'Y' %start

  if (ANSWER != 89) goto L_0009;

    //    30        print string("Yes!"); newline

  _imp_PRINTSTRING(_imp_str_literal("Yes!"));
  _imp_NEWLINE();

  //    31      %finish %else %if Answer = 'N' %start

  goto L_000A;
L_0009:;
  if (ANSWER != 78) goto L_000B;

    //    32        print string("No?"); newline

  _imp_PRINTSTRING(_imp_str_literal("No?"));
  _imp_NEWLINE();

  //    33      %finish %else %if Answer = 'X' %start

  goto L_000A;
L_000B:;
  if (ANSWER != 88) goto L_000C;

    //    34        print string("

  _imp_PRINTSTRING(_imp_str_literal("\nExiting on trapped END OF FILE event!."));

  //    35+ Exiting on trapped END OF FILE event!."); newlines(2)

  _imp_NEWLINES(2);

  //    36        %stop

  _imp_stop(0);

  //    37      %finish %else %start

L_000C:;

//    38        %monitor %and %stop

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

  //    39      %finish

L_000A:;

//    40    %repeat

  goto L_0008;

  //    41  %endofprogram

end_0:;
}