#include <perms.h>

//          Edinburgh IMP77 Compiler - Version 8.4
//
//     1  %begin; !6-valued logic simulator

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

  //     2
  //     3  %constinteger low=-2,falling=-1,rising=1,high=2
  //     4  %constinteger open=0,undef=((-1)>>1)!!(-1)
  //     5
  //     6  %ownrecord(*)%name nil==0

  static struct WHEN *NIL = 0;

  //     7  !%record(*)%name nil==record(0)

  struct HFM {
    union {
      struct {
        struct HFM *NEXT;
        int STATE;
        int SINCE;
      };
    };
  };

  // typedef struct PINF PINF;
  // typedef struct SIGF SIGF;
  // typedef struct EQF EQF;

  //     8
  //     9  %recordformat hfm(%record(hfm)%name next,%integer state,since)
  //    10  %constinteger slotmax=11; !slots @ 2 lines each, leaves 2 for command etc
  //    11  %constinteger eqmax=800;  !event queue cells
  //    12  %constinteger hmax=5000;  !heap words
  //    13
  //    14  %constinteger csize=5,psize=5,ssize=10; !size (in words) of heap records
  //    15  %constinteger hsize=3
  //    16  %recordformatspec pinf
  //    17  %recordformatspec sigf
  //    18  %recordformat compf(%record(compf)%name next,

  struct COMPF {
    union {
      struct {
        struct COMPF *NEXT;
        int TYPE;
        struct PINF *INS;
        struct PINF *OUTS;
        struct PINF *PRIVATE;
      };
    };
  };

  //    19+                     %integer type {indexes into behaviour switch},
  //    20+                     %record(pinf)%name ins,outs,private)
  //    21  %recordformat pinf(%record(pinf)%name next {pin in component},

  struct PINF {
    union {
      struct {
        struct PINF *NEXT;
        struct PINF *CHAIN;
        struct COMPF *COMP;
        struct SIGF *SIGNAL;
        int STATE;
      };
    };
  };

  //    22+                    chain {next pin in net},%record(compf)%name comp,
  //    23+                    %record(sigf)%name signal, %integer state)
  //    24  %recordformat sigf(%record(sigf)%name next {for identification},

  struct SIGF {
    union {
      struct {
        struct SIGF *NEXT;
        int STATE;
        struct PINF *FROM;
        struct PINF *TO;
        int SCREENSLOT;
        struct HFM *HISTORY;
        _imp_string15 NAME;
      };
    };
  };

  //    25+                    %integer state,%record(pinf)%name from,to,
  //    26+                    %integer screenslot,%record(hfm)%name history,
  //    27+                    %string(15)name)
  //    28  %recordformat eqf(%record(eqf)%name next,%record(pinf)%name pin,

  struct EQF {
    union {
      struct {
        struct EQF *NEXT;
        struct PINF *PIN;
        int STATE;
        int WHEN;
      };
    };
  };

  //    29+                   %integer state,when)
  //    30
  //    31  %record(sigf)%namearray slot(1:slotmax)

  struct SIGF *SLOT[11];

  //    32  %record(eqf)%name eventqueue,eclist

  struct EQF *EVENTQUEUE;
  struct EQF *ECLIST;

  //    33  %record(eqf)%array ecell(1:eqmax)

  struct EQF ECELL[800];

  //    34  %integer now=0

  int NOW;
  NOW = 0;

  //    35
  //    36  %integer heapspace=1

  int HEAPSPACE;
  HEAPSPACE = 1;

  //    37  %integerarray heap(1:hmax)

  int HEAP[5000];

  //    38  %record(sigf)%name nets==nil

  struct SIGF *NETS;
  NETS = (struct SIGF *)NIL;

  //    39  %record(compf)%name components==nil

  struct COMPF *COMPONENTS;
  COMPONENTS = (struct COMPF *)NIL;

  //    40
  //    41  %routine initialise arrays

  void INITIALISEARRAYS(void) {
    //    42  %integer i

    int I;

    //    43    slot(i)==nil %for i=1,1,slotmax

    // %for I = 1, 1, 11 %cycle
    {
      I = 0;
    L_0001:
      if (I == 11) goto L_0002;
      I += 1;
      SLOT[I - 1] = (struct SIGF *)NIL;
      goto L_0001;
    }

  L_0002:;

  //    44    ecell(i)_next==ecell(i-1) %for i=2,1,eqmax

  // %for I = 2, 1, 800 %cycle
    {
      I = 1;
    L_0004:
      if (I == 800) goto L_0005;
      I += 1;
      ECELL[I - 1].NEXT = (struct EQF *)/*?*/ &ECELL[I - 1 - 1];
      goto L_0004;
    }

  L_0005:;

  //    45    eclist==ecell(eqmax)

    ECLIST = (struct EQF *)/*?*/ &ECELL[799];

    //    46    ecell(1)_next==nil

    ECELL[0].NEXT = (struct EQF *)NIL;

    //    47    eventqueue==nil

    EVENTQUEUE = (struct EQF *)NIL;

    //    48  %end

    return;
  } /* end of INITIALISEARRAYS */

  //    49
  //    50  %record(*)%map new(%integer size)

  struct WHEN *NEW(int SIZE)
  {

    //    51  !This assumes that array elements with increasing
    //    52  !indices have increasing addresses
    //    53    %signal 15 %if heapspace>hmax

    if (HEAPSPACE <= 5000) goto L_0006;
    _imp_signal(15, 0, 0, "");
  L_0006:;

  //    54    heap(heapspace)=size; heapspace=heapspace+size+1

    HEAP[HEAPSPACE - 1] = SIZE;
    HEAPSPACE = HEAPSPACE + SIZE + 1;

    //    55    %result==record(addr(heap(heapspace-size)))

    return _imp_RECORD(_imp_ADDR(/*?*/ &HEAP[HEAPSPACE - SIZE - 1]));

    //    56  %end

  } /* end of NEW */

  //    57
  //    58  %record(pinf)%map newpin

  struct PINF *NEWPIN(void)
  {

    //    59  %record(pinf)%name x==new(psize)

    struct PINF *X;
    X = (struct PINF *)NEW(5);

    //    60    x=0; %result==x

    *X = (struct PINF){0};
    return X;

    //    61  %end

  } /* end of NEWPIN */

  //    62
  //    63  %record(compf)%map newcomp

  struct COMPF *NEWCOMP(void)
  {

    //    64  %record(compf)%name x==new(csize)

    struct COMPF *X;
    X = (struct COMPF *)NEW(5);

    //    65    x=0; %result==x

    *X = (struct COMPF){0};
    return X;

    //    66  %end

  } /* end of NEWCOMP */

  //    67
  //    68  %record(sigf)%map newsignal

  struct SIGF *NEWSIGNAL(void)
  {

    //    69  %record(sigf)%name x==new(ssize)

    struct SIGF *X;
    X = (struct SIGF *)NEW(10);

    //    70    x=0; x_state=undef; %result==x

    *X = (struct SIGF){0};
    X->STATE = -2147483648;
    return X;

    //    71  %end

  } /* end of NEWSIGNAL */

  //    72
  //    73  %record(hfm)%name history archive==nil

  struct HFM *HISTORYARCHIVE;
  HISTORYARCHIVE = (struct HFM *)NIL;

  //    74
  //    75  %record(hfm)%map get hist

  struct HFM *GETHIST(void)
  {

    //    76  %record(hfm)%name h

    struct HFM *H;

    //    77    h==history archive

    H = (struct HFM *)HISTORYARCHIVE;

    //    78    %if h==nil %then h==new(hsize) %else history archive==h_next

    if (_imp_ADDR((void *)(H)) != _imp_ADDR((void *)(NIL))) goto L_0007;

    H = (struct HFM *)NEW(3);
    goto L_0008;
  L_0007:;
    HISTORYARCHIVE = (struct HFM *)H->NEXT;
  L_0008:;

  //    79    h=0; %result==h

    *H = (struct HFM){0};
    return H;

    //    80  %end

  } /* end of GETHIST */

  //    81
  //    82  %routine put hist(%record(hfm)%name h)

  void PUTHIST(struct HFM * H) {
    //    83    h_next==history archive

    H->NEXT = (struct HFM *)HISTORYARCHIVE;

    //    84    history archive==h

    HISTORYARCHIVE = (struct HFM *)H;

    //    85  %end

    return;
  } /* end of PUTHIST */

  //    86
  //    87  %constinteger esc=27,cur='Y',graph='F',nograph='G',delete='O'
  //    88  %constinteger up='A',home='H',clearscreen='v',clearline='K'
  //    89  %constinteger insert='i',noinsert='j'
  //    90
  //    91  %routine escape(%integer x)

  void ESCAPE(int X) {
    //    92    printsymbol(esc); printsymbol(x)

    _imp_PRINTSYMBOL(27);
    _imp_PRINTSYMBOL(X);

    //    93  %end

    return;
  } /* end of ESCAPE */

  //    94
  //    95  %routine cursor(%integer x,y)

  void CURSOR(int X, int Y) {
    //    96    escape(cur); printsymbol(y+' '); printsymbol(x+' ')

    ESCAPE(89);
    _imp_PRINTSYMBOL(Y + 32);
    _imp_PRINTSYMBOL(X + 32);

    //    97  %end

    return;
  } /* end of CURSOR */

  //    98
  //    99  %integerfn upper(%integer old,new)

  int UPPER(int OLD, int NEW) {
    //   100    old=old+old %if |old|=rising

    if (_imp_IMOD(OLD) != 1) goto L_0009;
    OLD = OLD + OLD;
  L_0009:;

  //   101    new=new+new %if |new|=rising

    if (_imp_IMOD(NEW) != 1) goto L_000A;
    NEW = NEW + NEW;
  L_000A:;

  //   102    %if old=high %start

    if (OLD != 2) goto L_000B;

      //   103      %result='`' %if new=high

    if (NEW != 2) goto L_000C;
    return 96;
  L_000C:;

  //   104      %result='l' %if new=low

    if (NEW != -2) goto L_000D;
    return 108;
  L_000D:;

  //   105      %result='d' %if new=open

    if (NEW != 0) goto L_000E;
    return 100;
  L_000E:;

  //   106      %result='l'

    return 108;

    //   107    %finish

  L_000B:;

  //   108    %if old=low %start

    if (OLD != -2) goto L_000F;

      //   109      %result='s' %if new=high

    if (NEW != 2) goto L_0010;
    return 115;
  L_0010:;

  //   110      %result=' ' %if new=low

    if (NEW != -2) goto L_0011;
    return 32;
  L_0011:;

  //   111      %result='s' %if new=open

    if (NEW != 0) goto L_0012;
    return 115;
  L_0012:;

  //   112      %result=' '

    return 32;

    //   113    %finish

  L_000F:;

  //   114    %if old=open %start

    if (OLD != 0) goto L_0013;

      //   115      %result='d' %if new=high

    if (NEW != 2) goto L_0014;
    return 100;
  L_0014:;

  //   116      %result='l' %if new=low

    if (NEW != -2) goto L_0015;
    return 108;
  L_0015:;

  //   117      %result='d' %if new=open

    if (NEW != 0) goto L_0016;
    return 100;
  L_0016:;

  //   118      %result='l'

    return 108;

    //   119    %finish

  L_0013:;

  //   120    %result='s' %if new=high

    if (NEW != 2) goto L_0017;
    return 115;
  L_0017:;

  //   121    %result=' ' %if new=low

    if (NEW != -2) goto L_0018;
    return 32;
  L_0018:;

  //   122    %result=' ' %if new=open

    if (NEW != 0) goto L_0019;
    return 32;
  L_0019:;

  //   123    %result=' '

    return 32;

    //   124  %end

  } /* end of UPPER */

  //   125
  //   126  %integerfn lower(%integer old,new)

  int LOWER(int OLD, int NEW) {
    //   127    old=old+old %if |old|=rising

    if (_imp_IMOD(OLD) != 1) goto L_001A;
    OLD = OLD + OLD;
  L_001A:;

  //   128    new=new+new %if |new|=rising

    if (_imp_IMOD(NEW) != 1) goto L_001B;
    NEW = NEW + NEW;
  L_001B:;

  //   129    %if old=high %start

    if (OLD != 2) goto L_001C;

      //   130      %result=' ' %if new=high

    if (NEW != 2) goto L_001D;
    return 32;
  L_001D:;

  //   131      %result='e' %if new=low

    if (NEW != -2) goto L_001E;
    return 101;
  L_001E:;

  //   132      %result='e' %if new=open

    if (NEW != 0) goto L_001F;
    return 101;
  L_001F:;

  //   133      %result=' '

    return 32;

    //   134    %finish

  L_001C:;

  //   135    %if old=low %start

    if (OLD != -2) goto L_0020;

      //   136      %result='m' %if new=high

    if (NEW != 2) goto L_0021;
    return 109;
  L_0021:;

  //   137      %result='`' %if new=low

    if (NEW != -2) goto L_0022;
    return 96;
  L_0022:;

  //   138      %result='c' %if new=open

    if (NEW != 0) goto L_0023;
    return 99;
  L_0023:;

  //   139      %result='m'

    return 109;

    //   140    %finish

  L_0020:;

  //   141    %if old=open %start

    if (OLD != 0) goto L_0024;

      //   142      %result='m' %if new=high

    if (NEW != 2) goto L_0025;
    return 109;
  L_0025:;

  //   143      %result='c' %if new=low

    if (NEW != -2) goto L_0026;
    return 99;
  L_0026:;

  //   144      %result='c' %if new=open

    if (NEW != 0) goto L_0027;
    return 99;
  L_0027:;

  //   145      %result='m'

    return 109;

    //   146    %finish

  L_0024:;

  //   147    %result='e' %if new=high

    if (NEW != 2) goto L_0028;
    return 101;
  L_0028:;

  //   148    %result='e' %if new=low

    if (NEW != -2) goto L_0029;
    return 101;
  L_0029:;

  //   149    %result='%' %if new=open

    if (NEW != 0) goto L_002A;
    return 37;
  L_002A:;

  //   150    %result=' '

    return 32;

    //   151  %end

  } /* end of LOWER */

  //   152
  //   153  %routine refresh(%integer i)

  void REFRESH(int I) {
    //   154  %integer old,new

    int OLD;
    int NEW;

    //   155  %record(sigf)%name s

    struct SIGF *S;

    //   156  %record(hfm)%name h

    struct HFM *H;

    //   157    s==slot(i); %returnif s==nil

    S = (struct SIGF *)SLOT[I - 1];

    if (_imp_ADDR((void *)(S)) != _imp_ADDR((void *)(NIL))) goto L_002B;

    return;
  L_002B:;

  //   158    cursor(0,i+i+1); escape(clearline)

    CURSOR(0, I + I + 1);
    ESCAPE(75);

    //   159    cursor(0,i+i);   escape(clearline)

    CURSOR(0, I + I);
    ESCAPE(75);

    //   160    cursor(65,i+i+1); printstring(s_name)

    CURSOR(65, I + I + 1);
    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string255) tmp = S->NAME /*q*/;
          (_imp_string255 *)&tmp;
        })
    );

    //   161    cursor(65,i+i);   printstring(s_name); newline

    CURSOR(65, I + I);
    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string255) tmp = S->NAME /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    _imp_NEWLINE();

    //   162  !rest not in yet
    //   163  %end

    return;
  } /* end of REFRESH */

  // ?H unused
  // ?NEW unused
  // ?OLD unused
  //   164
  //   165  %routine log(%record(sigf)%name s,%integer old)

  void LOG(struct SIGF * S, int OLD) {
    //   166  %integer new,i

    int NEW;
    int I;

    //   167  %record(hfm)%name h,hh

    struct HFM *H;
    struct HFM *HH;

    //   168    escape(graph)

    ESCAPE(70);

    //   169    %if s==nil %start; ! Time has passed: old=ticks

    if (_imp_ADDR((void *)(S)) != _imp_ADDR((void *)(NIL))) goto L_002C;

      //   170      %while old>0 %cycle

  L_002D:;
    if (OLD <= 0) goto L_002E;

      //   171        old=old-1

    OLD = OLD - 1;

    //   172        escape(insert)

    ESCAPE(105);

    //   173        %for i=slotmax,-1,1 %cycle

    // %for I = 11,  -1, 1 %cycle
    {
      I = 12;
    L_002F:
      if (I == 1) goto L_0030;
      I -= 1;

      //   174          %unless slot(i)==nil %start

      if (_imp_ADDR((void *)(SLOT[I - 1])) == _imp_ADDR((void *)(NIL))) goto L_0032;

        //   175            new=slot(i)_state

      NEW = SLOT[I - 1]->STATE;

      //   176            cursor(0,i+i+1); escape(delete); cursor(63,i+i+1)

      CURSOR(0, I + I + 1);
      ESCAPE(79);
      CURSOR(63, I + I + 1);

      //   177            printsymbol(lower(new,new))

      _imp_PRINTSYMBOL(LOWER(NEW, NEW));

      //   178            cursor(0,i+i); escape(delete);   cursor(63,i+i)

      CURSOR(0, I + I);
      ESCAPE(79);
      CURSOR(63, I + I);

      //   179            printsymbol(upper(new,new))

      _imp_PRINTSYMBOL(UPPER(NEW, NEW));

      //   180            newline; !??

      _imp_NEWLINE();

      //   181          %finish

    L_0032:;

    //   182        %repeat

      goto L_002F;
    }

  L_0030:;

  //   183        escape(noinsert)

    ESCAPE(106);

    //   184      %repeat

    goto L_002D;
  L_002E:;

  //   185    %finishelsestart; ! Signal has changed: old=previous state

    goto L_0033;
  L_002C:;

  //   186      new=s_state

    NEW = S->STATE;

    //   187      h==s_history

    H = (struct HFM *)S->HISTORY;

    //   188      %if h==nil %start

    if (_imp_ADDR((void *)(H)) != _imp_ADDR((void *)(NIL))) goto L_0034;

      //   189        h==get hist; h_next==h; s_history==h

    H = (struct HFM *)GETHIST();
    H->NEXT = (struct HFM *)H;
    S->HISTORY = (struct SIGF *)H;

    //   190        h_since=now; h_state=new

    H->SINCE = NOW;
    H->STATE = NEW;

    //   191      %finishelsestart

    goto L_0035;
  L_0034:;

  //   192        old=h_state; ! overriding

    OLD = H->STATE;

    //   193        hh==get hist; hh_next==h_next; h_next==hh; s_history==hh

    HH = (struct HFM *)GETHIST();
    HH->NEXT = (struct HFM *)H->NEXT;
    H->NEXT = (struct HFM *)HH;
    S->HISTORY = (struct SIGF *)HH;

    //   194        hh_since=now; hh_state=new

    HH->SINCE = NOW;
    HH->STATE = NEW;

    //   195        h==hh

    H = (struct HFM *)HH;

    //   196      %finish

  L_0035:;

  //   197      %while h_next_next_since <= now-64 %cycle; !scavenge

  L_0036:;
    if (H->NEXT->NEXT->SINCE > NOW - 64) goto L_0037;

      //   198        hh==h_next; h_next==hh_next; put hist(hh)

    HH = (struct HFM *)H->NEXT;
    H->NEXT = (struct HFM *)HH->NEXT;
    PUTHIST(HH);

    //   199      %repeat

    goto L_0036;
  L_0037:;

  //   200      i=s_screenslot

    I = S->SCREENSLOT;

    //   201      %if i#0 %start

    if (I == 0) goto L_0038;

      //   202        cursor(63,i+i+1); printsymbol(lower(old,new))

    CURSOR(63, I + I + 1);
    _imp_PRINTSYMBOL(LOWER(OLD, NEW));

    //   203        cursor(63,i+i);   printsymbol(upper(old,new))

    CURSOR(63, I + I);
    _imp_PRINTSYMBOL(UPPER(OLD, NEW));

    //   204        newline; !??

    _imp_NEWLINE();

    //   205      %finish

  L_0038:;

  //   206    %finish

  L_0033:;

  //   207    escape(nograph); newline; !??

    ESCAPE(71);
    _imp_NEWLINE();

    //   208  %end

    return;
  } /* end of LOG */

  //   209
  //   210  %routine print(%integer state)

  void PRINT(int STATE) {
    //   211    %if state=high    %then printstring("high")      %elsec

    if (STATE != 2) goto L_0039;
    _imp_PRINTSTRING(_imp_str_literal("high"));
    goto L_003A;
  L_0039:;
    if (STATE != -2) goto L_003B;
    _imp_PRINTSTRING(_imp_str_literal("low"));
    goto L_003A;
  L_003B:;
    if (STATE != -2147483648) goto L_003C;
    _imp_PRINTSTRING(_imp_str_literal("undefined"));
    goto L_003A;
  L_003C:;
    if (STATE != 0) goto L_003D;
    _imp_PRINTSTRING(_imp_str_literal("open"));
    goto L_003A;
  L_003D:;
    if (STATE != 1) goto L_003E;
    _imp_PRINTSTRING(_imp_str_literal("rising"));
    goto L_003A;
  L_003E:;
    if (STATE != -1) goto L_003F;
    _imp_PRINTSTRING(_imp_str_literal("falling"));
  L_003F:;
  L_003A:;

  //   212+   %if state=low     %then printstring("low")       %elsec
  //   213+   %if state=undef   %then printstring("undefined") %elsec
  //   214+   %if state=open    %then printstring("open")      %elsec
  //   215+   %if state=rising  %then printstring("rising")    %elsec
  //   216+   %if state=falling %then printstring("falling")
  //   217    newline

    _imp_NEWLINE();

    //   218  %end

    return;
  } /* end of PRINT */
  auto void EXCITE(struct COMPF * COMP);

  //   219
  //   220
  //   221  %routinespec excite(%record(compf)%name c)
  //   222
  //   223  %routine propagate(%record(sigf)%name signal)

  void PROPAGATE(struct SIGF * SIGNAL) {
    //   224  %integer new,y,old

    int NEW;
    int Y;
    int OLD;

    //   225  %record(pinf)%name p

    struct PINF *P;

    //   226
    //   227    old=signal_state

    OLD = SIGNAL->STATE;

    //   228    p==signal_from

    P = (struct PINF *)SIGNAL->FROM;

    //   229    %if p==nil %start;     ! External input

    if (_imp_ADDR((void *)(P)) != _imp_ADDR((void *)(NIL))) goto L_0040;

      //   230      new=old; old=undef

    NEW = OLD;
    OLD = -2147483648;

    //   231    %finishelsestart;      ! Establish agreement from all sources

    goto L_0041;
  L_0040:;

  //   232      new=open

    NEW = 0;

    //   233      %cycle

  L_0042:;

  //   234        y=p_state; new=y %if new#y %and new=open

    Y = P->STATE;
    if (NEW == Y) goto L_0043;
    if (NEW != 0) goto L_0043;
    NEW = Y;
  L_0043:;

  //   235        new=undef %andexitif new#y %and y#open; !Conflict

    if (NEW == Y) goto L_0044;
    if (Y == 0) goto L_0044;
    NEW = -2147483648;
    goto L_0045;
  L_0044:;

  //   236        p==p_chain

    P = (struct PINF *)P->CHAIN;

    //   237      %repeatuntil p==nil

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0045;

    goto L_0042;
  L_0045:;

  //   238      %returnif signal_state=new

    if (SIGNAL->STATE != NEW) goto L_0046;
    return;
  L_0046:;

  //   239      %if |old|=rising %start; !Forced: Set all sources

    if (_imp_IMOD(OLD) != 1) goto L_0047;

      //   240        new=old+old; p==signal_from

    NEW = OLD + OLD;
    P = (struct PINF *)SIGNAL->FROM;

    //   241        %cycle

  L_0048:;

  //   242          p_state=new; p==p_chain

    P->STATE = NEW;
    P = (struct PINF *)P->CHAIN;

    //   243        %repeatuntil p==nil

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0049;

    goto L_0048;
  L_0049:;

  //   244        newline

    _imp_NEWLINE();

    //   245      %finish

  L_0047:;

  //   246      signal_state=new

    SIGNAL->STATE = NEW;

    //   247    %finish

  L_0041:;

  //   248
  //   249    log(signal,old)

    LOG(SIGNAL, OLD);

    //   250
    //   251  ! Excite all components with inputs connected to this signal
    //   252
    //   253    p==signal_to

    P = (struct PINF *)SIGNAL->TO;

    //   254    y=new; y=rising %if y=high; y=falling %if y=low

    Y = NEW;
    if (Y != 2) goto L_004A;
    Y = 1;
  L_004A:;
    if (Y != -2) goto L_004B;
    Y = -1;
  L_004B:;

  //   255    %whilenot p==nil %cycle

  L_004C:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_004D;

      //   256      p_state=y; excite(p_comp)

    P->STATE = Y;
    EXCITE(P->COMP);

    //   257      p_state=new; excite(p_comp); p==p_chain

    P->STATE = NEW;
    EXCITE(P->COMP);
    P = (struct PINF *)P->CHAIN;

    //   258    %repeat

    goto L_004C;
  L_004D:;

  //   259  %end

    return;
  } /* end of PROPAGATE */

  //   260
  //   261  %routine make(%record(pinf)%name pin,%integer new,when)

  void MAKE(struct PINF * PIN, int NEW, int WHEN) {
    //   262  %record(eqf)%name e,f

    struct EQF *E;
    struct EQF *F;

    //   263  %integer old

    int OLD;

    //   264    new=new+new %if |new|=rising

    if (_imp_IMOD(NEW) != 1) goto L_004E;
    NEW = NEW + NEW;
  L_004E:;

  //   265    %unless when=now %start;   ! Insert this event in event queue

    if (WHEN == NOW) goto L_004F;

      //   266      e==eclist; %signal 15 %if e==nil

    E = (struct EQF *)ECLIST;

    if (_imp_ADDR((void *)(E)) != _imp_ADDR((void *)(NIL))) goto L_0050;

    _imp_signal(15, 0, 0, "");
  L_0050:;

  //   267      eclist==e_next; e_next==nil

    ECLIST = (struct EQF *)E->NEXT;
    E->NEXT = (struct EQF *)NIL;

    //   268      e_pin==pin; e_state=new; e_when=when

    E->PIN = (struct EQF *)PIN;
    E->STATE = NEW;
    E->WHEN = WHEN;

    //   269      f==eventqueue

    F = (struct EQF *)EVENTQUEUE;

    //   270      %if f==nil %start

    if (_imp_ADDR((void *)(F)) != _imp_ADDR((void *)(NIL))) goto L_0051;

      //   271        eventqueue==e; %return

    EVENTQUEUE = (struct EQF *)E;
    return;

    //   272      %finish

  L_0051:;

  //   273      %if when<f_when %start

    if (WHEN >= F->WHEN) goto L_0052;

      //   274        e_next==f; eventqueue==e; %return

    E->NEXT = (struct EQF *)F;
    EVENTQUEUE = (struct EQF *)E;
    return;

    //   275      %finish

  L_0052:;

  //   276      %cycle

  L_0053:;

  //   277        %if f_next==nil %start

    if (_imp_ADDR((void *)(F->NEXT)) != _imp_ADDR((void *)(NIL))) goto L_0054;

      //   278          f_next==e; %return

    F->NEXT = (struct EQF *)E;
    return;

    //   279        %finish

  L_0054:;

  //   280        %if when<f_next_when %start

    if (WHEN >= F->NEXT->WHEN) goto L_0055;

      //   281          e_next==f_next; f_next==e; %return

    E->NEXT = (struct EQF *)F->NEXT;
    F->NEXT = (struct EQF *)E;
    return;

    //   282        %finish

  L_0055:;

  //   283        f==f_next

    F = (struct EQF *)F->NEXT;

    //   284      %repeat

    goto L_0053;

    //   285    %finish

  L_004F:;

  //   286    old=pin_state; %returnif old=new

    OLD = PIN->STATE;
    if (OLD != NEW) goto L_0056;
    return;
  L_0056:;

  //   287    pin_state=new; %returnif pin_signal==nil

    PIN->STATE = NEW;

    if (_imp_ADDR((void *)(PIN->SIGNAL)) != _imp_ADDR((void *)(NIL))) goto L_0057;

    return;
  L_0057:;

  //   288    propagate(pin_signal)

    PROPAGATE(PIN->SIGNAL);

    //   289  %end

    return;
  } /* end of MAKE */

  //   290
  //   291  %routine aftermath;  ! Flush event queue

  void AFTERMATH(void) {
    //   292  %record(eqf)%name e

    struct EQF *E;

    //   293    %cycle

  L_0058:;

  //   294      e==eventqueue; %returnif e==nil

    E = (struct EQF *)EVENTQUEUE;

    if (_imp_ADDR((void *)(E)) != _imp_ADDR((void *)(NIL))) goto L_0059;

    return;
  L_0059:;

  //   295      eventqueue==e_next; e_next==eclist; eclist==e

    EVENTQUEUE = (struct EQF *)E->NEXT;
    E->NEXT = (struct EQF *)ECLIST;
    ECLIST = (struct EQF *)E;

    //   296      log(nil,e_when-now)

    LOG(NIL, E->WHEN - NOW);

    //   297      now=e_when

    NOW = E->WHEN;

    //   298      make(e_pin,e_state,now)

    MAKE(E->PIN, E->STATE, NOW);

    //   299    %repeat

    goto L_0058;

    //   300  %end

  } /* end of AFTERMATH */

  //   301
  //   302  ! Basic logic primitives
  //   303  ! Note that NOT is just minus
  //   304
  //   305  %integerfn float(%integer x)

  int FLOAT(int X) {
    //   306    x=high %if x=open

    if (X != 0) goto L_005A;
    X = 2;
  L_005A:;

  //   307    x=x+x %if |x|=rising

    if (_imp_IMOD(X) != 1) goto L_005B;
    X = X + X;
  L_005B:;

  //   308    %result=x

    return X;

    //   309  %end

  } /* end of FLOAT */

  //   310
  //   311  %integerfn edgefloat(%integer x)

  int EDGEFLOAT(int X) {
    //   312    x=undef %if x=open

    if (X != 0) goto L_005C;
    X = -2147483648;
  L_005C:;

  //   313    %result=x

    return X;

    //   314  %end

  } /* end of EDGEFLOAT */

  //   315
  //   316  %integerfn setupfloat(%integer x)

  int SETUPFLOAT(int X) {
    //   317    x=high %if x=open %or x=falling

    if (X == 0) goto L_0003;
    if (X != -1) goto L_005D;
  L_0003:;
    X = 2;
  L_005D:;

  //   318    x=low %if x=rising

    if (X != 1) goto L_005E;
    X = -2;
  L_005E:;

  //   319    %result=x

    return X;

    //   320  %end

  } /* end of SETUPFLOAT */

  //   321
  //   322  %integerfn and(%integer x,y)

  int AND(int X, int Y) {
    //   323    %result=low %if x=low %or y=low

    if (X == -2) goto L_005F;
    if (Y != -2) goto L_0060;
  L_005F:;
    return -2;
  L_0060:;

  //   324    %result=undef %if x=undef %or y=undef

    if (X == -2147483648) goto L_0061;
    if (Y != -2147483648) goto L_0062;
  L_0061:;
    return -2147483648;
  L_0062:;

  //   325    %result=high

    return 2;

    //   326  %end

  } /* end of AND */

  //   327
  //   328  %integerfn or(%integer x,y)

  int OR(int X, int Y) {
    //   329    %result=high %if x=high %or y=high

    if (X == 2) goto L_0063;
    if (Y != 2) goto L_0064;
  L_0063:;
    return 2;
  L_0064:;

  //   330    %result=undef %if x=undef %or y=undef

    if (X == -2147483648) goto L_0065;
    if (Y != -2147483648) goto L_0066;
  L_0065:;
    return -2147483648;
  L_0066:;

  //   331    %result=low

    return -2;

    //   332  %end

  } /* end of OR */

  //   333
  //   334  %integerfn xor(%integer x,y)

  int XOR(int X, int Y) {
    //   335    %result=undef %if x=undef %or y=undef

    if (X == -2147483648) goto L_0067;
    if (Y != -2147483648) goto L_0068;
  L_0067:;
    return -2147483648;
  L_0068:;

  //   336    %result=low %if x=y

    if (X != Y) goto L_0069;
    return -2;
  L_0069:;

  //   337    %result=high

    return 2;

    //   338  %end

  } /* end of XOR */

  //   339
  //   340  %integerfn oc(%integer x); !open collector

  int OC(int X) {
    //   341    %result=open %if x=high %or x=rising

    if (X == 2) goto L_006A;
    if (X != 1) goto L_006B;
  L_006A:;
    return 0;
  L_006B:;

  //   342    %result=x

    return X;

    //   343  %end

  } /* end of OC */

  //   344
  //   345  %constinteger known=13
  //   346  %conststring(15)%array type(0:known)="???",

  const _imp_string15 TYPE[14] = {_imp_str_init("???"),  _imp_str_init("INV"),  _imp_str_init("INVO"),
                                  _imp_str_init("AND"),  _imp_str_init("NAND"), _imp_str_init("NANDO"),
                                  _imp_str_init("OR"),   _imp_str_init("NOR"),  _imp_str_init("NORO"),
                                  _imp_str_init("XOR"),  _imp_str_init("U74"),  _imp_str_init("TSBUF"),
                                  _imp_str_init("U374"), _imp_str_init("U123")};

  //   347+ "INV",  "INVO",
  //   348+ "AND",  "NAND",
  //   349+ "NANDO","OR",
  //   350+ "NOR",  "NORO",
  //   351+ "XOR",  "U74",
  //   352+ "TSBUF","U374",
  //   353+ "U123"
  //   354
  //   355  %routine fail(%record(compf)%name c,%record(sigf)%name s,%string(15)m)

  void FAIL(struct COMPF * C, struct SIGF * S, _imp_string15 M) {
    //   356  %record(pinf)%name p

    struct PINF *P;

    //   357  %integer n

    int N;

    //   358    printstring(m)

    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string15) tmp = M /*q*/;
          (_imp_string255 *)&tmp;
        })
    );

    //   359    %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_006C;

      //   360      printstring(" Net "); printstring(s_name)

    _imp_PRINTSTRING(_imp_str_literal(" Net "));
    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string255) tmp = S->NAME /*q*/;
          (_imp_string255 *)&tmp;
        })
    );

    //   361      p==s_from; n=0

    P = (struct PINF *)S->FROM;
    N = 0;

    //   362      %whilenot p==nil %cycle

  L_006D:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_006E;

      //   363        n=n+1; p==p_chain

    N = N + 1;
    P = (struct PINF *)P->CHAIN;

    //   364      %repeat

    goto L_006D;
  L_006E:;

  //   365      write(n,1)

    _imp_WRITE(N, 1);

    //   366      p==s_to; n=0

    P = (struct PINF *)S->TO;
    N = 0;

    //   367      %whilenot p==nil %cycle

  L_006F:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0070;

      //   368        n=n+1; p==p_chain

    N = N + 1;
    P = (struct PINF *)P->CHAIN;

    //   369      %repeat

    goto L_006F;
  L_0070:;

  //   370      write(n,1); newline

    _imp_WRITE(N, 1);
    _imp_NEWLINE();

    //   371    %finish

  L_006C:;

  //   372    %unless c==nil %start

    if (_imp_ADDR((void *)(C)) == _imp_ADDR((void *)(NIL))) goto L_0071;

      //   373      printstring(type(c_type)); printstring(" (")

    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string15) tmp = TYPE[C->TYPE] /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    _imp_PRINTSTRING(_imp_str_literal(" ("));

    //   374      p==c_ins

    P = (struct PINF *)C->INS;

    //   375      %whilenot p==nil %cycle

  L_0072:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0073;

      //   376        printstring(p_signal_name); p==p_next; printsymbol(',') %unless p==nil

    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string255) tmp = P->SIGNAL->NAME /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    P = (struct PINF *)P->NEXT;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0074;

    _imp_PRINTSYMBOL(44);
  L_0074:;

  //   377      %repeat

    goto L_0072;
  L_0073:;

  //   378      printsymbol('/')

    _imp_PRINTSYMBOL(47);

    //   379      p==c_outs

    P = (struct PINF *)C->OUTS;

    //   380      %whilenot p==nil %cycle

  L_0075:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0076;

      //   381        printstring(p_signal_name); p==p_next; printsymbol(',') %unless p==nil

    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string255) tmp = P->SIGNAL->NAME /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    P = (struct PINF *)P->NEXT;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_0077;

    _imp_PRINTSYMBOL(44);
  L_0077:;

  //   382      %repeat

    goto L_0075;
  L_0076:;

  //   383      printsymbol(')'); newline

    _imp_PRINTSYMBOL(41);
    _imp_NEWLINE();

    //   384    %finish

  L_0071:;

  //   385    %signal 15

    _imp_signal(15, 0, 0, "");

    //   386  %end

    return;
  } /* end of FAIL */

  //   387
  //   388  %routine excite(%record(compf)%name comp)

  void EXCITE(struct COMPF * COMP) {
    //   389  %record(pinf)%name in1,in2,more,out

    struct PINF *IN1;
    struct PINF *IN2;
    struct PINF *MORE;
    struct PINF *OUT;

    //   390  %integer i1,i2

    int I1;
    int I2;

    //   391  %switch s(0:known)

    int S_index;
    int S_line;
    char *S_file;
    static const void *S[14] = {&&case_S_missing, &&case_S_missing, &&case_S_missing, &&case_S_missing,
                                &&case_S_missing, &&case_S_missing, &&case_S_missing, &&case_S_missing,
                                &&case_S_missing, &&case_S_missing, &&case_S_missing, &&case_S_missing,
                                &&case_S_missing, &&case_S_missing};

    //   392  %switch t(3:9)

    int T_index;
    int T_line;
    char *T_file;
    static const void *T[7] = {&&case_T_missing, &&case_T_missing, &&case_T_missing, &&case_T_missing,
                               &&case_T_missing, &&case_T_missing, &&case_T_missing};

    //   393
    //   394    more==nil; in2==nil

    MORE = (struct PINF *)NIL;
    IN2 = (struct PINF *)NIL;

    //   395    in1==comp_ins

    IN1 = (struct PINF *)COMP->INS;

    //   396    %unless in1==nil %start

    if (_imp_ADDR((void *)(IN1)) == _imp_ADDR((void *)(NIL))) goto L_0078;

      //   397      i1=in1_state; in2==in1_next

    I1 = IN1->STATE;
    IN2 = (struct PINF *)IN1->NEXT;

    //   398      %unless in2==nil %start

    if (_imp_ADDR((void *)(IN2)) == _imp_ADDR((void *)(NIL))) goto L_0079;

      //   399        more==in2_next; i2=in2_state

    MORE = (struct PINF *)IN2->NEXT;
    I2 = IN2->STATE;

    //   400      %finish

  L_0079:;

  //   401    %finish

  L_0078:;

  //   402    out==comp_outs

    OUT = (struct PINF *)COMP->OUTS;

    //   403    ->s(comp_type)

    S_line = __LINE__;
    S_file = __FILE__;
    S_index = COMP->TYPE;
    goto case_S_dispatch;

    //   404
    //   405  s(9): {xor}    i1=xor(float(i1),float(i2)); ->generic

  case_S_9:;
    I1 = XOR(FLOAT(I1), FLOAT(I2));
    goto U_1000;

    //   406  s(3): {and}

  case_S_3:;

  //   407  s(4): {nand}

  case_S_4:;

  //   408  s(5): {nando}  i1=and(float(i1),float(i2)); ->generic

  case_S_5:;
    I1 = AND(FLOAT(I1), FLOAT(I2));
    goto U_1000;

    //   409  s(6): {or}

  case_S_6:;

  //   410  s(7): {nor}

  case_S_7:;

  //   411  s(8): {noro}   i1=or(float(i1),float(i2))

  case_S_8:;
    I1 = OR(FLOAT(I1), FLOAT(I2));

    //   412  generic:

  U_1000:;

  //   413    ->t(comp_type) %if more==nil

    if (_imp_ADDR((void *)(MORE)) != _imp_ADDR((void *)(NIL))) goto L_007B;

    T_line = __LINE__;
    T_file = __FILE__;
    T_index = COMP->TYPE;
    goto case_T_dispatch;
  L_007B:;

  //   414    i2=more_state; more==more_next; ->s(comp_type)

    I2 = MORE->STATE;
    MORE = (struct PINF *)MORE->NEXT;
    S_line = __LINE__;
    S_file = __FILE__;
    S_index = COMP->TYPE;
    goto case_S_dispatch;

    //   415
    //   416  t(9): {xor}

  case_T_9:;

  //   417  t(6): {or}

  case_T_6:;

  //   418  t(3): {and}    make(out,i1,now+1); %return

  case_T_3:;
    MAKE(OUT, I1, NOW + 1);
    return;

    //   419  s(1): {inv}

  case_S_1:;

  //   420  t(7): {nor}

  case_T_7:;

  //   421  t(4): {nand}   make(out,-float(i1),now+1); %return

  case_T_4:;
    MAKE(OUT, -FLOAT(I1), NOW + 1);
    return;

    //   422  s(2): {invo}

  case_S_2:;

  //   423  t(8): {noro}

  case_T_8:;

  //   424  t(5): {nando}  make(out,oc(-float(i1)),now+1); %return

  case_T_5:;
    MAKE(OUT, OC(-FLOAT(I1)), NOW + 1);
    return;

    //   425
    //   426  s(10):{u74}

  case_S_10:;

  //   427    %begin

    { /*%begin*/

      //   428    %integer d,s0,r0,c

      int D;
      int S0;
      int R0;
      int C;

      //   429    %record(pinf)%name out0

      struct PINF *OUT0;

      //   430
      //   431      d=setupfloat(i1); s0=float(i2); r0=float(more_state)

      D = SETUPFLOAT(I1);
      S0 = FLOAT(I2);
      R0 = FLOAT(MORE->STATE);

      //   432      c=edgefloat(more_next_state)

      C = EDGEFLOAT(MORE->NEXT->STATE);

      //   433      out0==out_next

      OUT0 = (struct PINF *)OUT->NEXT;

      //   434
      //   435      %if r0=undef %start

      if (R0 != -2147483648) goto L_007D;

        //   436        make(out,high,now+1) %if s0=low

      if (S0 != -2) goto L_007E;
      MAKE(OUT, 2, NOW + 1);
    L_007E:;

    //   437      %finishelseif s0=undef %start

      goto L_007F;
    L_007D:;
      if (S0 != -2147483648) goto L_0080;

        //   438        make(out0,high,now+1) %if r0=low

      if (R0 != -2) goto L_0081;
      MAKE(OUT0, 2, NOW + 1);
    L_0081:;

    //   439      %finishelseif r0=low %and s0=low %start

      goto L_007F;
    L_0080:;
      if (R0 != -2) goto L_0082;
      if (S0 != -2) goto L_0082;

        //   440        make(out,high,now+1); make(out0,high,now+1)

      MAKE(OUT, 2, NOW + 1);
      MAKE(OUT0, 2, NOW + 1);

      //   441      %finishelseif r0=low %start

      goto L_007F;
    L_0082:;
      if (R0 != -2) goto L_0083;

        //   442        make(out,low,now+1); make(out0,high,now+1)

      MAKE(OUT, -2, NOW + 1);
      MAKE(OUT0, 2, NOW + 1);

      //   443      %finishelseif s0=low %start

      goto L_007F;
    L_0083:;
      if (S0 != -2) goto L_0084;

        //   444        make(out,high,now+1); make(out0,low,now+1)

      MAKE(OUT, 2, NOW + 1);
      MAKE(OUT0, -2, NOW + 1);

      //   445        %if c=rising %and (d=low %or d=undef) %start

      if (C != 1) goto L_0085;
      if (D == -2) goto L_0086;
      if (D != -2147483648) goto L_0085;
    L_0086:;

    //   446          make(out0,-d,now+2); make(out0,low,now+3)

      MAKE(OUT0, -D, NOW + 2);
      MAKE(OUT0, -2, NOW + 3);

      //   447        %finish

    L_0085:;

    //   448      %finishelseif c=rising %start

      goto L_007F;
    L_0084:;
      if (C != 1) goto L_0087;

        //   449        make(out,d,now+2); make(out0,-d,now+2)

      MAKE(OUT, D, NOW + 2);
      MAKE(OUT0, -D, NOW + 2);

      //   450      %finish

    L_0087:;
    L_007F:;

    //   451    %end

      goto end_1000;
    end_1000:;
    }

    //   452    %return

    return;

    //   453
    //   454  s(11): {tsbuf: non-inverting, low-active enable}

  case_S_11:;

  //   455    i1=float(i1); i2=float(i2)

    I1 = FLOAT(I1);
    I2 = FLOAT(I2);

    //   456    %if i2=low %then i2=i1 %elsec

    if (I2 != -2) goto L_0088;
    I2 = I1;
    goto L_0089;
  L_0088:;
    if (I2 != 2) goto L_008A;
    I2 = 0;
    goto L_0089;
  L_008A:;
    I2 = -2147483648;
  L_0089:;

  //   457+   %if i2=high %then i2=open %else i2=undef
  //   458    make(out,i2,now+1)

    MAKE(OUT, I2, NOW + 1);

    //   459    %return

    return;

    //   460
    //   461  s(12): {u374: clock, enable\ i(0:7) / o(0:7)}

  case_S_12:;

  //   462  !%begin
  //   463  !%record(pinf)%namearray in,state,out(0:7)
  //   464  !%record(pinf)%name p
  //   465  !%integer i
  //   466  !  p==comp_private
  //   467  !  %if p==nil %start
  //   468  !    %for i=0,1,7 %cycle
  //   469  !      p==newpin; state(i)==p; p_comp==comp
  //   470  !    %repeat
  //   471  !    comp_private==state(0)
  //   472  !    %for i=0,1,6 %cycle
  //   473  !      state(i)_next==state(i+1)
  //   474  !    %repeat
  //   475  !    state(7)_next==nil
  //   476  !  %finishelsestart
  //   477  !    %for i=0,1,7 %cycle
  //   478  !      state(i)==p; p==p_next
  //   479  !    %repeat
  //   480  !  %finish
  //   481  !  p==comp_outs
  //   482  !  %for i=0,1,7 %cycle
  //   483  !    out(i)==p; p==p_next
  //   484  !  %repeat
  //   485  !  p==more
  //   486  !  %for i=0,1,7 %cycle
  //   487  !    in(i)==p; p==p_next
  //   488  !  %repeat
  //   489  !  %if i1=rising %start
  //   490  !    state(i)_state=setupfloat(in(i)_state) %for i=0,1,7
  //   491  !  %finish
  //   492  !  i2=float(i2)
  //   493  !  %if i2=low %start
  //   494  !    make(out(i),state(i)_state,now+1) %for i=0,1,7
  //   495  !  %finishelsestart
  //   496  !    %if i2=high %then i2=open %else i2=undef
  //   497  !    make(out(i),i2,now+1) %for i=0,1,7
  //   498  !  %finish
  //   499  !%end
  //   500    %return

    return;

    //   501
    //   502  s(13): {u123: a0, b, c0, timeout / q, q0}

  case_S_13:;

  //   503    %begin

    { /*%begin*/

      //   504   %integer a0,b,c0,timeout

      int A0;
      int B;
      int C0;
      int TIMEOUT;

      //   505    %record(pinf)%name out0

      struct PINF *OUT0;

      //   506    a0=float(i1); b=float(i2); c0=float(more_state)

      A0 = FLOAT(I1);
      B = FLOAT(I2);
      C0 = FLOAT(MORE->STATE);

      //   507    timeout=more_next_state

      TIMEOUT = MORE->NEXT->STATE;

      //   508    out0==out_next

      OUT0 = (struct PINF *)OUT->NEXT;

      //   509    %if c0=low %start

      if (C0 != -2) goto L_008B;

        //   510      make(out,low,now+1); make(out0,high,now+1)

      MAKE(OUT, -2, NOW + 1);
      MAKE(OUT0, 2, NOW + 1);

      //   511    %finishelseif c0=undef %start

      goto L_008C;
    L_008B:;
      if (C0 != -2147483648) goto L_008D;

        //   512      make(out,undef,now+1); make(out0,undef,now+1)

      MAKE(OUT, -2147483648, NOW + 1);
      MAKE(OUT0, -2147483648, NOW + 1);

      //   513    %finishelsestart

      goto L_008C;
    L_008D:;

    //   514      b=and(-a0,b)

      B = AND(-A0, B);

      //   515      %if b=high %and out_state=low %start

      if (B != 2) goto L_008E;
      if (OUT->STATE != -2) goto L_008E;

        //   516        make(out,high,now+1)

      MAKE(OUT, 2, NOW + 1);

      //   517        make(out0,low,now+1)

      MAKE(OUT0, -2, NOW + 1);

      //   518      %finishelseif |timeout|=rising %start

      goto L_008F;
    L_008E:;
      if (_imp_IMOD(TIMEOUT) != 1) goto L_0090;

        //   519        make(out,low,now+1)

      MAKE(OUT, -2, NOW + 1);

      //   520        make(out0,high,now+1)

      MAKE(OUT0, 2, NOW + 1);

      //   521      %finish

    L_0090:;
    L_008F:;

    //   522    %finish

    L_008C:;

    //   523    %end

      goto end_1001;
    end_1001:;
    }

    //   524    %return

    return;

    //   525
    //   526  s(0):

  case_S_0:;

  //   527  %end

    return;

  case_S_dispatch:
    if (S_index < 0 || S_index > 13)
      _imp_signalf(6, 3, S_index, "->S(%d) out of bounds at %s line %d", S_index, S_file, S_line);
    goto *S[S_index - 0];

  case_S_missing:
    _imp_signalf(8, 2, S_index, "switch jump to undefined label S(%d): at %s line %d", S_index, S_file, S_line);

  case_T_dispatch:
    if (T_index < 3 || T_index > 9)
      _imp_signalf(6, 3, T_index, "->T(%d) out of bounds at %s line %d", T_index, T_file, T_line);
    goto *T[T_index - 3];

  case_T_missing:
    _imp_signalf(8, 2, T_index, "switch jump to undefined label T(%d): at %s line %d", T_index, T_file, T_line);
  } /* end of EXCITE */

  //   528
  //   529  %string(15)atom,pend=""

  _imp_string15 ATOM;
  _imp_string15 PEND;

  _imp_strncpy(/*?*/ &PEND, ({
                 __typeof__(_imp_string255) tmp; /*B*/
                 tmp = _imp_str_literal("");
                 (void *)&tmp;
               }),
               /*max:*/ 15);

  //   530  %integer sym=nl

  int SYM;
  SYM = 10;

  //   531  %constbyteintegerarray symtype(0:127)=

  const unsigned char SYMTYPE[128] = {
      [0 ... 32] = 1,   [33 ... 35] = 0,  2, [37 ... 39] = 0, 2, 2, 0, 0, 2, 2, 0, 2, [48 ... 63] = 0, [64 ... 96] = 0,
      [97 ... 122] = 3, [123 ... 127] = 0};

  //   532+ 1(33),0(3),2,0(3),2,2,0,0,2,2,0,2,0(16),0(33),3(26),0(5)
  //   533  !          $      ( )     , -   /
  //   534  ! 0 normal 1 separator 2 special 3 lower-case
  //   535
  //   536  %routine readatom

  void READATOM(void) {
    //   537  %integer st

    int ST;

    //   538    %unless pend="" %start

    if (_imp_strcmp((_imp_string *)/*?*/ &PEND, (_imp_string *)/*?*/ _imp_str_literal_ptr("")) == 0) goto L_0091;

      //   539      atom=pend; pend=""; %return

    _imp_strncpy(/*?*/ &ATOM, ({
                   __typeof__(_imp_string15) tmp; /*B*/
                   tmp = PEND;
                   (void *)&tmp;
                 }),
                 /*max:*/ 15);

    _imp_strncpy(/*?*/ &PEND, ({
                   __typeof__(_imp_string255) tmp; /*B*/
                   tmp = _imp_str_literal("");
                   (void *)&tmp;
                 }),
                 /*max:*/ 15);

    return;

    //   540    %finish

  L_0091:;

  //   541    %cycle

  L_0092:;

  //   542      %cycle

  L_0093:;

  //   543        st=symtype(sym&127); %exitunless st=1

    ST = SYMTYPE[SYM & 127];
    if (ST == 1) goto L_0094;
    goto L_0095;
  L_0094:;

  //   544        readsymbol(sym)

    _imp_READSYMBOL(/*?*/ &SYM);

    //   545      %repeat

    goto L_0093;
  L_0095:;

  //   546      %exitunless sym='$'

    if (SYM == 36) goto L_0096;
    goto L_0097;
  L_0096:;

  //   547      readsymbol(sym) %until sym='$' %or sym=nl

  L_0098:;
    _imp_READSYMBOL(/*?*/ &SYM);
    if (SYM == 36) goto L_0099;
    if (SYM == 10) goto L_0099;
    goto L_0098;
  L_0099:;

  //   548      readsymbol(sym)

    _imp_READSYMBOL(/*?*/ &SYM);

    //   549    %repeat

    goto L_0092;
  L_0097:;

  //   550    sym=sym-32 %if st=3

    if (ST != 3) goto L_009A;
    SYM = SYM - 32;
  L_009A:;

  //   551    atom=tostring(sym)

    _imp_strncpy(/*?*/ &ATOM, ({
                   __typeof__(_imp_string1) tmp; /*B*/
                   tmp = _imp_TOSTRING(SYM);
                   (void *)&tmp;
                 }),
                 /*max:*/ 15);

    //   552    %if st=2 %start; !Special on its own

    if (ST != 2) goto L_009B;

      //   553      %if sym='-' %start; ! "->" or "/" or "-" equivalent

    if (SYM != 45) goto L_009C;

      //   554        atom="/"

    _imp_strncpy(/*?*/ &ATOM, ({
                   __typeof__(_imp_string255) tmp; /*B*/
                   tmp = _imp_str_literal("/");
                   (void *)&tmp;
                 }),
                 /*max:*/ 15);

    //   555        readsymbol(sym); %returnunless sym='>'

    _imp_READSYMBOL(/*?*/ &SYM);
    if (SYM == 62) goto L_009D;
    return;
  L_009D:;

  //   556      %finish

  L_009C:;

  //   557      readsymbol(sym); %return

    _imp_READSYMBOL(/*?*/ &SYM);
    return;

    //   558    %finish

  L_009B:;

  //   559    readsymbol(sym)

    _imp_READSYMBOL(/*?*/ &SYM);

    //   560    %cycle

  L_009E:;

  //   561      st=symtype(sym&127); sym=sym-32 %and st=0 %if st=3

    ST = SYMTYPE[SYM & 127];
    if (ST != 3) goto L_009F;
    SYM = SYM - 32;
    ST = 0;
  L_009F:;

  //   562      %exitunless st=0

    if (ST == 0) goto L_00A0;
    goto L_00A1;
  L_00A0:;

  //   563      atom=atom.tostring(sym) %unless length(atom)=15

    if (*_imp_LENGTH((_imp_string255 *)/*p*/ /*?*/ &ATOM) == 15) goto L_00A2;

    _imp_strncpy(/*?*/ &ATOM, ({
                   __typeof__(_imp_string255) tmp; /*B*/
                   tmp = *({
                     _imp_string255 tmp = _imp_join((_imp_string *)/*?*/ &ATOM, ({
                                                      __typeof__(_imp_string1) tmp; /*E*/
                                                      tmp = _imp_TOSTRING(SYM);
                                                      (void *)&tmp;
                                                    }));
                     (_imp_string255 *)&tmp;
                   });
                   (void *)&tmp;
                 }),
                 /*max:*/ 15);

  L_00A2:;

  //   564      readsymbol(sym)

    _imp_READSYMBOL(/*?*/ &SYM);

    //   565    %repeat

    goto L_009E;
  L_00A1:;

  //   566  %end

    return;
  } /* end of READATOM */

  //   567
  //   568  %record(sigf)%map findsignal

  struct SIGF *FINDSIGNAL(void)
  {

    //   569  %record(sigf)%name s

    struct SIGF *S;

    //   570    s==nets

    S = (struct SIGF *)NETS;

    //   571    %whilenot s==nil %cycle

  L_00A3:;

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00A4;

      //   572      %result==s %if s_name=atom

    if (_imp_strcmp((_imp_string *)/*?*/ &S->NAME, (_imp_string *)/*?*/ &ATOM) != 0) goto L_00A5;

    return S;
  L_00A5:;

  //   573      s==s_next

    S = (struct SIGF *)S->NEXT;

    //   574    %repeat

    goto L_00A3;
  L_00A4:;

  //   575    s==newsignal; s_next==nets; nets==s; s_name=atom

    S = (struct SIGF *)NEWSIGNAL();
    S->NEXT = (struct SIGF *)NETS;
    NETS = (struct SIGF *)S;

    _imp_strncpy(/*?*/ &S->NAME, ({
                   __typeof__(_imp_string15) tmp; /*B*/
                   tmp = ATOM;
                   (void *)&tmp;
                 }),
                 /*max:*/ 255);

    //   576    %result==s

    return S;

    //   577  %end

  } /* end of FINDSIGNAL */

  //   578
  //   579  %routine readcomponent

  void READCOMPONENT(void) {
    //   580  %record(compf)%name c

    struct COMPF *C;

    //   581  %record(pinf)%name p,plist

    struct PINF *P;
    struct PINF *PLIST;

    //   582  %record(sigf)%name s

    struct SIGF *S;

    //   583  %integer t,slashes

    int T;
    int SLASHES;

    //   584
    //   585  %record(pinf)%map reverse(%record(pinf)%name this)

    struct PINF *REVERSE(struct PINF * THIS)
    {

      //   586  %record(pinf)%name tail,next

      struct PINF *TAIL;
      struct PINF *NEXT;

      //   587    tail==nil; %result==nil %if this==nil

      TAIL = (struct PINF *)NIL;

      if (_imp_ADDR((void *)(THIS)) != _imp_ADDR((void *)(NIL))) goto L_00A6;

      return NIL;
    L_00A6:;

    //   588    %cycle

    L_00A7:;

    //   589      next==this_next; this_next==tail; tail==this

      NEXT = (struct PINF *)THIS->NEXT;
      THIS->NEXT = (struct PINF *)TAIL;
      TAIL = (struct PINF *)THIS;

      //   590      %result==this %if next==nil; this==next

      if (_imp_ADDR((void *)(NEXT)) != _imp_ADDR((void *)(NIL))) goto L_00A8;

      return THIS;
    L_00A8:;
      THIS = (struct PINF *)NEXT;

      //   591    %repeat

      goto L_00A7;

      //   592  %end

    } /* end of REVERSE */

    //   593
    //   594  !%record(pinf)%map reversecopy(%record(pinf)%name list)
    //   595  !%record(pinf)%name x,y
    //   596  !  x==nil
    //   597  !  %cycle
    //   598  !    %result==x %if list==nil
    //   599  !    y==newpin; y_next==x; x==y
    //   600  !    y_comp==c; y_signal==list_signal
    //   601  !    list==list_next
    //   602  !  %repeat
    //   603  !%end
    //   604  !
    //   605  !%record(pinf)%map append(%record(pinf)%name tail,list)
    //   606  !%record(pinf)%name p
    //   607  !  %result==tail %if list==nil
    //   608  !  p==list; p==p_next %whilenot p_next==nil; p_next==tail
    //   609  !  %result==list
    //   610  !%end
    //   611
    //   612    readatom; %signal 9 %if atom="END"

    READATOM();

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("END")) != 0) goto L_00A9;

    _imp_signal(9, 0, 0, "");
  L_00A9:;

  //   613    %for t=1,1,known %cycle

  // %for T = 1, 1, 13 %cycle
    {
      T = 0;
    L_00AA:
      if (T == 13) goto L_00AB;
      T += 1;

      //   614      ->ok %if type(t)=atom

      if (_imp_strcmp((_imp_string *)/*?*/ &TYPE[T], (_imp_string *)/*?*/ &ATOM) != 0) goto L_00AD;

      goto U_1001;
    L_00AD:;

    //   615    %repeat

      goto L_00AA;
    }

  L_00AB:;

  //   616    printstring("Unknown component "); printstring(atom); newline

    _imp_PRINTSTRING(_imp_str_literal("Unknown component "));
    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string15) tmp = ATOM /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    _imp_NEWLINE();

    //   617    t=0

    T = 0;

    //   618  ok: c==newcomp; c_type=t

  U_1001:;
    C = (struct COMPF *)NEWCOMP();
    C->TYPE = T;

    //   619    c_next==components; components==c

    C->NEXT = (struct COMPF *)COMPONENTS;
    COMPONENTS = (struct COMPF *)C;

    //   620    slashes=0; plist==nil

    SLASHES = 0;
    PLIST = (struct PINF *)NIL;

    //   621    readatom

    READATOM();

    //   622    printstring("( expected") %and newline %unless atom="("

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("(")) == 0) goto L_00AE;

    _imp_PRINTSTRING(_imp_str_literal("( expected"));
    _imp_NEWLINE();
  L_00AE:;

  //   623  !Non-ESDL-compatible notation:  comp(ins{{/inouts}/outs})
  //   624  !  readatom
  //   625  !  %cycle
  //   626  !    %if atom="/" %or atom=")" %start
  //   627  !      %if slashes=0 %start
  //   628  !        c_ins==reverse(plist); %exitif atom=")"
  //   629  !        slashes=1
  //   630  !      %finishelsestart
  //   631  !        %if atom=")" %start
  //   632  !          c_outs==append(reverse(plist),c_outs); %exit
  //   633  !        %finish
  //   634  !        c_ins==append(reversecopy(plist),c_ins)
  //   635  !        c_outs==reverse(plist)
  //   636  !      %finish
  //   637  !      plist==nil
  //   638  !      readatom
  //   639  !    %finishelsestart
  //   640  !      printstring("Unexpected (") %and newline %if atom="("
  //   641  !      printstring("Unexpected ,") %and newline %if atom=","
  //   642  !      s==nil; s==findsignal %unless atom="?"
  //   643  !      p==newpin; p_next==plist; plist==p
  //   644  !      p_comp==c; p_signal==s; p_state=open %if s==nil
  //   645  !      readatom
  //   646  !      %if atom="," %then readatom %elsestart
  //   647  !        printstring(", expected") %and newline %unless atom="/" %or atom=")"
  //   648  !      %finish
  //   649  !    %finish
  //   650  !  %repeat
  //   651  !ESDL-compatible notation: comp(ins)->outs
  //   652  ! This requires pending atom and disallows inouts
  //   653    %cycle

  L_00AF:;

  //   654      readatom

    READATOM();

    //   655      %if atom=")" %or atom="," %or atom="/" %start

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(")")) == 0) goto L_00B0;

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(",")) == 0) goto L_00B0;

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("/")) != 0) goto L_00B1;

  L_00B0:;

  //   656        printstring(atom); printstring(" not expected"); newline

    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string15) tmp = ATOM /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    _imp_PRINTSTRING(_imp_str_literal(" not expected"));
    _imp_NEWLINE();

    //   657        %exit

    goto L_00B2;

    //   658      %finish

  L_00B1:;

  //   659      s==nil; s==findsignal %unless atom="?"

    S = (struct SIGF *)NIL;

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("?")) == 0) goto L_00B3;

    S = (struct SIGF *)FINDSIGNAL();
  L_00B3:;

  //   660      p==newpin; p_next==plist; plist==p

    P = (struct PINF *)NEWPIN();
    P->NEXT = (struct PINF *)PLIST;
    PLIST = (struct PINF *)P;

    //   661      p_comp==c; p_signal==s; p_state=open %if s==nil

    P->COMP = (struct PINF *)C;
    P->SIGNAL = (struct PINF *)S;

    if (_imp_ADDR((void *)(S)) != _imp_ADDR((void *)(NIL))) goto L_00B4;

    P->STATE = 0;
  L_00B4:;

  //   662      readatom

    READATOM();

    //   663      %exitif atom=")" %or atom="/"

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(")")) == 0) goto L_00B5;

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("/")) != 0) goto L_00B6;

  L_00B5:;
    goto L_00B2;
  L_00B6:;

  //   664      printstring(", expected") %and newline %unless atom=","

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(",")) == 0) goto L_00B7;

    _imp_PRINTSTRING(_imp_str_literal(", expected"));
    _imp_NEWLINE();
  L_00B7:;

  //   665    %repeat

    goto L_00AF;
  L_00B2:;

  //   666    readatom %if atom=")"

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(")")) != 0) goto L_00B8;

    READATOM();
  L_00B8:;

  //   667    printstring("-> expected") %and newline %unless atom="/"

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("/")) == 0) goto L_00B9;

    _imp_PRINTSTRING(_imp_str_literal("-> expected"));
    _imp_NEWLINE();
  L_00B9:;

  //   668    c_ins==reverse(plist); plist==nil

    C->INS = (struct COMPF *)REVERSE(PLIST);
    PLIST = (struct PINF *)NIL;

    //   669    %cycle

  L_00BA:;

  //   670      readatom

    READATOM();

    //   671      printstring(", not expected") %and newline %if atom=","

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(",")) != 0) goto L_00BB;

    _imp_PRINTSTRING(_imp_str_literal(", not expected"));
    _imp_NEWLINE();
  L_00BB:;

  //   672      s==nil; s==findsignal %unless atom="?"

    S = (struct SIGF *)NIL;

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr("?")) == 0) goto L_00BC;

    S = (struct SIGF *)FINDSIGNAL();
  L_00BC:;

  //   673      p==newpin; p_next==plist; plist==p

    P = (struct PINF *)NEWPIN();
    P->NEXT = (struct PINF *)PLIST;
    PLIST = (struct PINF *)P;

    //   674      p_comp==c; p_signal==s; p_state=open %if s==nil

    P->COMP = (struct PINF *)C;
    P->SIGNAL = (struct PINF *)S;

    if (_imp_ADDR((void *)(S)) != _imp_ADDR((void *)(NIL))) goto L_00BD;

    P->STATE = 0;
  L_00BD:;

  //   675      readatom; %exitunless atom=","

    READATOM();

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(",")) == 0) goto L_00BE;

    goto L_00BF;
  L_00BE:;

  //   676    %repeat

    goto L_00BA;
  L_00BF:;

  //   677    pend=atom %unless atom=")"

    if (_imp_strcmp((_imp_string *)/*?*/ &ATOM, (_imp_string *)/*?*/ _imp_str_literal_ptr(")")) == 0) goto L_00C0;

    _imp_strncpy(/*?*/ &PEND, ({
                   __typeof__(_imp_string15) tmp; /*B*/
                   tmp = ATOM;
                   (void *)&tmp;
                 }),
                 /*max:*/ 15);

  L_00C0:;

  //   678    c_outs==reverse(plist); plist==nil

    C->OUTS = (struct COMPF *)REVERSE(PLIST);
    PLIST = (struct PINF *)NIL;

    //   679    p==c_ins

    P = (struct PINF *)C->INS;

    //   680    %whilenot p==nil %cycle

  L_00C1:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_00C2;

      //   681      s==p_signal

    S = (struct SIGF *)P->SIGNAL;

    //   682      p_chain==s_to %and s_to==p %unless s==nil

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00C3;

    P->CHAIN = (struct PINF *)S->TO;
    S->TO = (struct SIGF *)P;
  L_00C3:;

  //   683      p==p_next

    P = (struct PINF *)P->NEXT;

    //   684    %repeat

    goto L_00C1;
  L_00C2:;

  //   685    p==c_outs

    P = (struct PINF *)C->OUTS;

    //   686    %whilenot p==nil %cycle

  L_00C4:;

    if (_imp_ADDR((void *)(P)) == _imp_ADDR((void *)(NIL))) goto L_00C5;

      //   687      s==p_signal

    S = (struct SIGF *)P->SIGNAL;

    //   688      p_chain==s_from %and s_from==p %unless s==nil

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00C6;

    P->CHAIN = (struct PINF *)S->FROM;
    S->FROM = (struct SIGF *)P;
  L_00C6:;

  //   689      p==p_next

    P = (struct PINF *)P->NEXT;

    //   690    %repeat

    goto L_00C4;
  L_00C5:;

  //   691  %end

    return;
  } /* end of READCOMPONENT */

  //   692
  //   693  %routine simulate

  void SIMULATE(void) {
    //   694  %integer command,i

    int COMMAND;
    int I;

    //   695  %record(compf)%name c

    struct COMPF *C;

    //   696  %record(sigf)%name s

    struct SIGF *S;

    //   697
    //   698  %routine identify

    void IDENTIFY(void) {
      //   699    readatom

      READATOM();

      //   700    s==findsignal

      S = (struct SIGF *)FINDSIGNAL();

      //   701    %if s_from==nil %and s_to==nil %start

      if (_imp_ADDR((void *)(S->FROM)) != _imp_ADDR((void *)(NIL))) goto L_00C7;

      if (_imp_ADDR((void *)(S->TO)) != _imp_ADDR((void *)(NIL))) goto L_00C7;

        //   702      s==nil; printstring("Not connected"); newline

      S = (struct SIGF *)NIL;
      _imp_PRINTSTRING(_imp_str_literal("Not connected"));
      _imp_NEWLINE();

      //   703    %finish

    L_00C7:;

    //   704  %end

      return;
    } /* end of IDENTIFY */

    //   705
    //   706    initialise arrays

    INITIALISEARRAYS();

    //   707    escape(clearscreen); newline

    ESCAPE(118);
    _imp_NEWLINE();

    //   708
    //   709  %cycle

  L_00C8:;

  //   710    escape(home); escape(clearline); newline

    ESCAPE(72);
    ESCAPE(75);
    _imp_NEWLINE();

    //   711    prompt(tostring(esc).tostring(up)."scuovpdr+-?:")

    _imp_PROMPT(
        *({
          __typeof__(_imp_string255) tmp = *({
            _imp_string255 tmp = _imp_join((_imp_string *)/*?*/ &*({
                                             _imp_string255 tmp = _imp_join(({
                                                                              __typeof__(_imp_string1) tmp; /*D*/
                                                                              tmp = _imp_TOSTRING(27);
                                                                              (void *)&tmp;
                                                                            }),
                                                                            ({
                                                                              __typeof__(_imp_string1) tmp; /*E*/
                                                                              tmp = _imp_TOSTRING(65);
                                                                              (void *)&tmp;
                                                                            }));
                                             (_imp_string255 *)&tmp;
                                           }),
                                           (_imp_string *)/*?*/ _imp_str_literal_ptr("scuovpdr+-?:"));
            (_imp_string255 *)&tmp;
          }) /*q*/;
          (_imp_string15 *)&tmp;
        })
    );

    //   712    escape(clearline); newline

    ESCAPE(75);
    _imp_NEWLINE();

    //   713    readsymbol(command) %until command>' '

  L_00C9:;
    _imp_READSYMBOL(/*?*/ &COMMAND);
    if (COMMAND > 32) goto L_00CA;
    goto L_00C9;
  L_00CA:;

  //   714    command=command!32

    COMMAND = COMMAND | 32;

    //   715    %stopif command=':'

    if (COMMAND != 58) goto L_00CB;
    _imp_stop(0);
  L_00CB:;

  //   716    %if command='-' %start

    if (COMMAND != 45) goto L_00CC;

      //   717      identify

    IDENTIFY();

    //   718      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00CD;

      //   719        i=s_screenslot

    I = S->SCREENSLOT;

    //   720        %unless i=0 %start

    if (I == 0) goto L_00CE;

      //   721          slot(i)==nil

    SLOT[I - 1] = (struct SIGF *)NIL;

    //   722          s_screenslot=0

    S->SCREENSLOT = 0;

    //   723          cursor(0,i+i+1); escape(clearline)

    CURSOR(0, I + I + 1);
    ESCAPE(75);

    //   724          cursor(0,i+i);   escape(clearline)

    CURSOR(0, I + I);
    ESCAPE(75);

    //   725          newline; !??

    _imp_NEWLINE();

    //   726        %finish

  L_00CE:;

  //   727      %finish

  L_00CD:;

  //   728    %finishelseif command='+' %start

    goto L_00CF;
  L_00CC:;
    if (COMMAND != 43) goto L_00D0;

      //   729      identify

    IDENTIFY();

    //   730      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00D1;

      //   731        %if s_screenslot=0 %start

    if (S->SCREENSLOT != 0) goto L_00D2;

      //   732          %for i=1,1,slotmax %cycle

      // %for I = 1, 1, 11 %cycle
    {
      I = 0;
    L_00D3:
      if (I == 11) goto L_00D4;
      I += 1;

      //   733            %if slot(i)==nil %start

      if (_imp_ADDR((void *)(SLOT[I - 1])) != _imp_ADDR((void *)(NIL))) goto L_00D6;

        //   734              slot(i)==s; s_screenslot=i

      SLOT[I - 1] = (struct SIGF *)S;
      S->SCREENSLOT = I;

      //   735              refresh(i)

      REFRESH(I);

      //   736              %exit

      goto L_00D4;

      //   737            %finish

    L_00D6:;

    //   738          %repeat

      goto L_00D3;
    }

  L_00D4:;

  //   739        %finish

  L_00D2:;

  //   740      %finish

  L_00D1:;

  //   741    %finishelseif command='r' %start

    goto L_00CF;
  L_00D0:;
    if (COMMAND != 114) goto L_00D7;

      //   742      refresh(i) %for i=1,1,slotmax

      // %for I = 1, 1, 11 %cycle
    {
      I = 0;
    L_00D8:
      if (I == 11) goto L_00D9;
      I += 1;
      REFRESH(I);
      goto L_00D8;
    }

  L_00D9:;

  //   743    %finishelseif command='?' %start

    goto L_00CF;
  L_00D7:;
    if (COMMAND != 63) goto L_00DA;

      //   744      identify

    IDENTIFY();

    //   745      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00DB;

      //   746        printstring(atom); printstring(" = "); print(s_state); newline

    _imp_PRINTSTRING(
        *({
          __typeof__(_imp_string15) tmp = ATOM /*q*/;
          (_imp_string255 *)&tmp;
        })
    );
    _imp_PRINTSTRING(_imp_str_literal(" = "));
    PRINT(S->STATE);
    _imp_NEWLINE();

    //   747      %finish

  L_00DB:;

  //   748    %finishelseif command='s' %start

    goto L_00CF;
  L_00DA:;
    if (COMMAND != 115) goto L_00DC;

      //   749      identify

    IDENTIFY();

    //   750      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00DD;

      //   751        s_state=rising; propagate(s)

    S->STATE = 1;
    PROPAGATE(S);

    //   752        s_state=high; propagate(s)

    S->STATE = 2;
    PROPAGATE(S);

    //   753        aftermath

    AFTERMATH();

    //   754      %finish

  L_00DD:;

  //   755    %finishelseif command='c' %start

    goto L_00CF;
  L_00DC:;
    if (COMMAND != 99) goto L_00DE;

      //   756      identify

    IDENTIFY();

    //   757      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00DF;

      //   758        s_state=falling; propagate(s)

    S->STATE = -1;
    PROPAGATE(S);

    //   759        s_state=low; propagate(s)

    S->STATE = -2;
    PROPAGATE(S);

    //   760        aftermath

    AFTERMATH();

    //   761      %finish

  L_00DF:;

  //   762    %finishelseif command='u' %start

    goto L_00CF;
  L_00DE:;
    if (COMMAND != 117) goto L_00E0;

      //   763      identify

    IDENTIFY();

    //   764      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00E1;

      //   765        s_state=undef; propagate(s)

    S->STATE = -2147483648;
    PROPAGATE(S);

    //   766        aftermath

    AFTERMATH();

    //   767      %finish

  L_00E1:;

  //   768    %finishelseif command='o' %start

    goto L_00CF;
  L_00E0:;
    if (COMMAND != 111) goto L_00E2;

      //   769      identify

    IDENTIFY();

    //   770      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00E3;

      //   771        s_state=open; propagate(s)

    S->STATE = 0;
    PROPAGATE(S);

    //   772        aftermath

    AFTERMATH();

    //   773      %finish

  L_00E3:;

  //   774    %finishelseif command='v' %start

    goto L_00CF;
  L_00E2:;
    if (COMMAND != 118) goto L_00E4;

      //   775      identify

    IDENTIFY();

    //   776      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00E5;

      //   777      %if |s_state|=high %start

    if (_imp_IMOD(S->STATE) != 2) goto L_00E6;

      //   778        s_state=-s_state//2; propagate(s)

    S->STATE = -(((long)S->STATE / (long)2));
    PROPAGATE(S);

    //   779        s_state=s_state<<1; propagate(s)

    S->STATE = S->STATE << 1;
    PROPAGATE(S);

    //   780        aftermath

    AFTERMATH();

    //   781      %finish

  L_00E6:;

  //   782      %finish

  L_00E5:;

  //   783    %finishelseif command='p' %start

    goto L_00CF;
  L_00E4:;
    if (COMMAND != 112) goto L_00E7;

      //   784      identify

    IDENTIFY();

    //   785      %unless s==nil %start

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00E8;

      //   786      %if |s_state|=high %start

    if (_imp_IMOD(S->STATE) != 2) goto L_00E9;

      //   787        s_state=-s_state//2; propagate(s)

    S->STATE = -(((long)S->STATE / (long)2));
    PROPAGATE(S);

    //   788        s_state=s_state<<1; propagate(s)

    S->STATE = S->STATE << 1;
    PROPAGATE(S);

    //   789        aftermath

    AFTERMATH();

    //   790        s_state=-s_state//2; propagate(s)

    S->STATE = -(((long)S->STATE / (long)2));
    PROPAGATE(S);

    //   791        s_state=s_state<<1; propagate(s)

    S->STATE = S->STATE << 1;
    PROPAGATE(S);

    //   792        aftermath

    AFTERMATH();

    //   793      %finish

  L_00E9:;

  //   794      %finish

  L_00E8:;

  //   795    %finishelseif command='d' %start

    goto L_00CF;
  L_00E7:;
    if (COMMAND != 100) goto L_00EA;

      //   796      s==nets

    S = (struct SIGF *)NETS;

    //   797      %cycle

  L_00EB:;

  //   798        %if s_state=undef %start

    if (S->STATE != -2147483648) goto L_00EC;

      //   799          prompt(s_name." = "); readsymbol(sym)

    _imp_PROMPT(
        *({
          __typeof__(_imp_string255) tmp = *({
            _imp_string255 tmp =
                _imp_join((_imp_string *)/*?*/ &S->NAME, (_imp_string *)/*?*/ _imp_str_literal_ptr(" = "));
            (_imp_string255 *)&tmp;
          }) /*q*/;
          (_imp_string15 *)&tmp;
        })
    );
    _imp_READSYMBOL(/*?*/ &SYM);

    //   800          %if sym#nl %start

    if (SYM == 10) goto L_00ED;

      //   801            sym=sym!32

    SYM = SYM | 32;

    //   802            %if sym='h' %start

    if (SYM != 104) goto L_00EE;

      //   803              s_state=rising; propagate(s)

    S->STATE = 1;
    PROPAGATE(S);

    //   804              s_state=high; propagate(s)

    S->STATE = 2;
    PROPAGATE(S);

    //   805            %finishelseif sym='l' %start

    goto L_00EF;
  L_00EE:;
    if (SYM != 108) goto L_00F0;

      //   806              s_state=falling; propagate(s)

    S->STATE = -1;
    PROPAGATE(S);

    //   807              s_state=low; propagate(s)

    S->STATE = -2;
    PROPAGATE(S);

    //   808            %finishelseif sym='o' %start

    goto L_00EF;
  L_00F0:;
    if (SYM != 111) goto L_00F1;

      //   809              s_state=open; propagate(s)

    S->STATE = 0;
    PROPAGATE(S);

    //   810            %finishelse sym=0

    goto L_00EF;
  L_00F1:;
    SYM = 0;
  L_00EF:;

  //   811            aftermath %unless sym=0

    if (SYM == 0) goto L_00F2;
    AFTERMATH();
  L_00F2:;

  //   812            readsymbol(sym) %until sym=nl

  L_00F3:;
    _imp_READSYMBOL(/*?*/ &SYM);
    if (SYM == 10) goto L_00F4;
    goto L_00F3;
  L_00F4:;

  //   813          %finish

  L_00ED:;

  //   814        %finish

  L_00EC:;

  //   815        s==s_next

    S = (struct SIGF *)S->NEXT;

    //   816      %repeatuntil s==nil

    if (_imp_ADDR((void *)(S)) == _imp_ADDR((void *)(NIL))) goto L_00F5;

    goto L_00EB;
  L_00F5:;

  //   817    %finish

  L_00EA:;
  L_00CF:;

  //   818  %repeat

    goto L_00C8;

    //   819  %end

  } /* end of SIMULATE */

  // ?C unused
  //   820
  //   821  %integer stream=1

  int STREAM;
  STREAM = 1;

  //   822
  //   823  %onevent 9 %start

  if (!_imp_on_event(9)) goto L_00F6;

    //   824    %stopif stream=0; stream=0

  if (STREAM != 0) goto L_00F7;
  _imp_stop(0);
L_00F7:;
  STREAM = 0;

  //   825  %finish

L_00F6:;

//   826
//   827  selectinput(stream)

  _imp_SELECTINPUT(STREAM);

  //   828  simulate %if stream=0

  if (STREAM != 0) goto L_00F8;
  SIMULATE();
L_00F8:;

//   829  %cycle

L_00F9:;

//   830    readcomponent

  READCOMPONENT();

  //   831  %repeat

  goto L_00F9;

  //   832
  //   833  %endofprogram

end_0:;
}