]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/spin/pangen1.h
ip/ipconfig: use ewrite() to enable routing command for sendra
[plan9front.git] / sys / src / cmd / spin / pangen1.h
1 /***** spin: pangen1.h *****/
2
3 /*
4  * This file is part of the public release of Spin. It is subject to the
5  * terms in the LICENSE file that is included in this source directory.
6  * Tool documentation is available at http://spinroot.com
7  */
8
9 static const char *Code2a[] = { /* the tail of procedure run() */
10         "       if (state_tables)",
11         "       { if (dodot) exit(0);",
12         "         printf(\"\\nTransition Type: \");",
13         "         printf(\"A=atomic; D=d_step; L=local; G=global\\n\");",
14         "         printf(\"Source-State Labels: \");",
15         "         printf(\"p=progress; e=end; a=accept;\\n\");",
16         "#ifdef MERGED",
17         "         printf(\"Note: statement merging was used. Only the first\\n\");",
18         "         printf(\"      stmnt executed in each merge sequence is shown\\n\");",
19         "         printf(\"      (use spin -a -o3 to disable statement merging)\\n\");",
20         "#endif",
21         "         pan_exit(0);",
22         "       }",
23         "#if defined(BFS) && defined(TRIX)", /* before iniglobals */
24         "       { int i;",
25         "         for (i = 0; i < MAXPROC+1; i++)",
26         "         {     processes[i] = (TRIX_v6 *) emalloc(sizeof(TRIX_v6));",
27         "               processes[i]->body = (uchar *) emalloc(Maxbody * sizeof(char));",
28         "         }",
29         "         for (i = 0; i < MAXQ+1; i++)",
30         "         {     channels[i] = (TRIX_v6 *) emalloc(sizeof(TRIX_v6));",
31         "               channels[i]->body = (uchar *) emalloc(Maxbody * sizeof(char));",
32         "       } }",
33         "#endif",
34         "#ifdef BFS_PAR",
35         "       bfs_setup_mem();",
36         "       #ifdef COLLAPSE",
37         "       /* this must be the very first allocation from the shared heap */",
38         "               #ifdef BFS_SEP_HASH",
39         "               ncomps = (ulong *) emalloc((ulong)((256+2) * sizeof(ulong)));",
40         "               #else",
41         "               ncomps = (ulong *) sh_pre_malloc((ulong)((256+2) * sizeof(ulong)));",
42         "               #endif",
43         "       #endif",
44         "#endif",
45         "       iniglobals(258); /* arg outside range of pids */",
46         "#if defined(VERI) && !defined(NOREDUCE) && !defined(NP) && !defined(BFS) && !defined(HAS_LTL)",
47         "       if (!state_tables",
48         "       #ifdef HAS_CODE",
49         "       && !readtrail",
50         "       #endif",
51         "       #if NCORE>1",
52         "       && core_id == 0",
53         "       #endif",
54         "       )",
55         "       { printf(\"warning: for p.o. reduction to be valid \");",
56         "         printf(\"the never claim must be stutter-invariant\\n\");",
57         "         printf(\"(never claims generated from LTL \");",
58         "         printf(\"formulae are stutter-invariant)\\n\");",
59         "       }",
60         "#endif",
61         "       UnBlock;        /* disable rendez-vous */",
62         "#ifdef BITSTATE",
63         "       sinit();",
64         "#else",
65         "       hinit();",
66         "#endif",
67         "#if defined(FULLSTACK) && defined(BITSTATE)",
68         "       onstack_init();",
69         "#endif",
70         "#if defined(CNTRSTACK) && !defined(BFS)",
71         "       LL = (uchar *) emalloc(ONE_L<<(ssize-3));",
72         "#endif",
73         "       stack   = (_Stack *) emalloc(sizeof(_Stack));",
74         "       svtack  = (Svtack *) emalloc(sizeof(Svtack));",
75         "       /* a place to point for Pptr of non-running procs: */",
76         "       noqptr = noptr  = (uchar *) emalloc(Maxbody * sizeof(char));",
77         "#if defined(SVDUMP) && defined(VERBOSE)",
78         "       if (vprefix > 0)",
79         "               (void) write(svfd, (uchar *) &vprefix, sizeof(int));",
80         "#endif",
81         "#ifdef VERI",
82         "       Addproc(VERI,1);        /* pid = 0, priority 1 */",
83         "       #if NCLAIMS>1",
84         "       if (claimname != NULL)",
85         "       {       whichclaim = find_claim(claimname);",
86         "               select_claim(whichclaim);",
87         "       }",
88         "       #endif",
89         "#endif",
90         "       active_procs(); /* started after never */",
91         "#ifdef EVENT_TRACE",
92         "       now._event = start_event;",
93         "       reached[EVENT_TRACE][start_event] = 1;",
94         "#endif",
95
96         "#ifdef HAS_CODE",
97         "       globinit();",
98         "#endif",
99         "#ifdef BITSTATE",
100         "go_again:",
101         "#endif",
102         "       do_the_search();",
103         "#ifdef BITSTATE",
104         "       if (--Nrun > 0 && HASH_CONST[++HASH_NR])", /* last entry is 0 */
105         "       {       printf(\"Run %%d:\\n\", HASH_NR);",
106         "               wrap_stats();",
107         "               printf(\"\\n\");",
108         "               if (udmem)      /* Dillinger 3/2/09 */",
109         "               {       memset(SS, 0, udmem);",
110         "               } else",
111         "               {       memset(SS, 0, ONE_L<<(ssize-3));",
112         "               }",
113                 "#ifdef CNTRSTACK",
114         "               memset(LL, 0, ONE_L<<(ssize-3));",
115                 "#endif",
116                 "#ifdef FULLSTACK",
117         "               memset((uchar *) S_Tab, 0, ",
118         "               maxdepth*sizeof(H_el *));",
119                 "#endif",
120         "               nstates=nlinks=truncs=truncs2=ngrabs = 0;",
121         "               nlost=nShadow=hcmp = 0;",
122         "               Fa=Fh=Zh=Zn = 0;",
123         "               PUT=PROBE=ZAPS=Ccheck=Cholds = 0;",
124         "               goto go_again;",
125         "       }",
126         "#endif",
127         "}",
128         "#ifdef HAS_PRIORITY",
129         "extern int highest_priority(int, short, Trans *);",
130         "extern int get_priority(int);",
131         "extern int set_priority(int, int);",
132         "#endif",
133         "#ifdef SPIN_HEAP",
134         "void *",
135         "spin_malloc(int n)     /* reserved for use by Modex generated models */",
136         "{      char *spin_heap_ptr = &(now.spin_heap[now.spin_heap_n]);",
137         "       if (now.spin_heap_n + n >= sizeof(now.spin_heap))",
138         "       {       Uerror(\"spin_heap limit reached\");",
139         "       }",
140         "       now.spin_heap_n += n;",
141         "       return spin_heap_ptr;",
142         "}",
143         "void",
144         "spin_free(void *unused)",
145         "{      unused; /* ignore */",
146         "}",
147         "#endif",
148         "int",
149         "spin_join(int p, void **unused)",
150         "{      /* fprintf(stderr, \"join %%d when %%d\\n \", p, now._nr_pr); */",
151         "       return (now._nr_pr <= p);       /* process *p has stopped */",
152         "}",
153         "",
154         "int",
155         "spin_mutex_free(int *m)",
156         "{      return (*m == 0);",
157         "}",
158         "",
159         "int",
160         "spin_mutex_lock(int *m)",
161         "{      *m = 1;",
162         "       return 1;",
163         "}",
164         "void",
165         "spin_mutex_destroy(int *m)",
166         "{      *m = 0;",
167         "}",
168         "void",
169         "spin_mutex_unlock(int *m)",
170         "{      *m = 0;",
171         "}",
172         "void",
173         "spin_mutex_init(int *m, void *val)",
174         "{",
175         "       if (!val)", /* the 2nd arg must be NULL, for now */
176         "       {       *m = 0;",
177         "       } else",
178         "       {       Uerror(\"pthread_mutex_init: unsupported non-default init\");",
179         "       }",
180         "}",
181         "",
182         "int",
183         "spin_cond_wait(int *cond, int *lck)",  /*release and re-acquire lock *lck */
184         "{      /* this version does not scale very far alas */",
185         "       if (((P0 *)this)->_pid + 1 >= WS*8)", /* 32 or 64 */
186         "       {       Uerror(\"pid exceeds range supported by pthread_cond_wait\");",
187         "       }",
188         "       if (((*cond)&1) == 0)",         /* repeatedly tested, so: */
189         "       {       spin_mutex_unlock(lck);", /* avoid double counting */
190         "               *cond |= (1<<(((P0 *)this)->_pid + 1));",
191         "               return 0;",     /* blocked, must test again */
192         "       } else",
193         "       {       /* if other processes are already waiting */",
194         "               /* while our wait flag is 0, then they should go first */",
195         "               if (((*cond)&(~(1 | (1<<(((P0 *)this)->_pid + 1))))) != 0)",
196         "               {       spin_mutex_unlock(lck);",
197         "                       return 0;", /* wait for the others to go first */
198         "               }",
199         "               *cond &= ~1;",  /* clear the 'go' bit andy wait flag */
200         "               *cond &= ~(1<<(((P0 *)this)->_pid + 1));",
201         "               return 1;",     /* okay to proceed */
202         "       }",
203         "}",
204         "void",
205         "spin_cond_signal(int *cond)",
206         "{",
207         "       if ( ((*cond)&(~1)) != 0 )", /* procs are waiting */
208         "       {       *cond |= 1;",   /* set the 'go' bit */
209         "       }",
210         "}",
211         "",
212         "#ifdef HAS_PROVIDED",
213         "       int provided(int, uchar, int, Trans *);",
214         "#endif",
215         "#ifdef BFS_PAR",
216         "       extern void bfs_shutdown(const char *);",
217         "#endif",
218         "",
219         "#if NCORE>1",
220         "       #define GLOBAL_LOCK     (0)",
221         "       #ifndef CS_N",
222         "               #define CS_N            (256*NCORE)", /* must be a power of 2 */
223         "       #endif",
224
225         "       #ifdef NGQ",    /* no global queue */
226         "               #define NR_QS           (NCORE)",
227         "               #define CS_NR           (CS_N+1)        /* 2^N + 1, nr critical sections */",
228         "               #define GQ_RD           GLOBAL_LOCK",   /* not really used in this mode */
229         "               #define GQ_WR           GLOBAL_LOCK",   /* but just in case... */
230         "               #define CS_ID           (1 + (int) (j1_spin & (CS_N-1))) /* mask: 2^N - 1, zero reserved */",
231         "               #define QLOCK(n)        (1+n)", /* overlaps first n zones of hashtable */
232         "       #else",
233         "               #define NR_QS           (NCORE+1)",     /* add a global queue */
234         "               #define CS_NR           (CS_N+3)",      /* 2 extra locks for global q */
235         "               #define GQ_RD           (1)",           /* read access to global q */
236         "               #define GQ_WR           (2)",           /* write access to global q */
237         "               #define CS_ID           (3 + (int) (j1_spin & (CS_N-1)))",
238         "               #define QLOCK(n)        (3+n)",/* overlaps first n zones of hashtable */
239         "       #endif",
240         "",
241         "       #ifndef SEP_STATE",
242         "               #define enter_critical(w)       e_critical(w)",
243         "               #define leave_critical(w)       x_critical(w)",
244         "       #else",
245         "               #ifdef NGQ",
246         "                       #define enter_critical(w)       { if (w < 1+NCORE) e_critical(w); }",
247         "                       #define leave_critical(w)       { if (w < 1+NCORE) x_critical(w); }",
248         "               #else",
249         "                       #define enter_critical(w)       { if (w < 3+NCORE) e_critical(w); }",
250         "                       #define leave_critical(w)       { if (w < 3+NCORE) x_critical(w); }",
251         "               #endif",
252         "       #endif",
253         "",
254         "       int",
255         "       cpu_printf(const char *fmt, ...)", /* only used with VERBOSE/CHECK/DEBUG */
256         "       {       va_list args;",
257         "               enter_critical(GLOBAL_LOCK);    /* printing */",
258         "               printf(\"cpu%%d: \", core_id);",
259         "               fflush(stdout);",
260         "               va_start(args, fmt);",
261         "               vprintf(fmt, args);",
262         "               va_end(args);",
263         "               fflush(stdout);",
264         "               leave_critical(GLOBAL_LOCK);",
265         "               return 1;",
266         "       }",
267         "#else",
268         "       #define enter_critical(w)       /* none */",
269         "       #define leave_critical(w)       /* none */",
270         "",
271         "       int",
272         "       cpu_printf(const char *fmt, ...)",
273         "       {       va_list args;",
274         "               va_start(args, fmt);",
275         "               vprintf(fmt, args);",
276         "               va_end(args);",
277         "               return 1;",
278         "       }",
279         "#endif",
280
281 #ifndef PRINTF
282         "int",
283         "Printf(const char *fmt, ...)",
284         "{      /* Make sure the args to Printf",
285         "        * are always evaluated (e.g., they",
286         "        * could contain a run stmnt)",
287         "        * but do not generate the output",
288         "        * during verification runs",
289         "        * unless explicitly wanted",
290         "        * If this fails on your system",
291         "        * compile SPIN itself -DPRINTF",
292         "        * and this code is not generated",
293         "        */",
294         "#ifdef HAS_CODE",
295         "       if (readtrail)",
296         "       {       va_list args;",
297         "               va_start(args, fmt);",
298         "               vprintf(fmt, args);",
299         "               va_end(args);",
300         "               return 1;",
301         "       }",
302         "#endif",
303         "#ifdef PRINTF",
304         "       va_list args;",
305         "       va_start(args, fmt);",
306         "       vprintf(fmt, args);",
307         "       va_end(args);",
308         "#endif",
309         "       return 1;",
310         "}",
311 #endif
312         "extern void printm(int);",
313
314         "#ifndef SC",
315         "#define getframe(i)    &trail[i];",
316         "#else",
317         "static long HHH, DDD, hiwater;",
318         "static long CNT1, CNT2;",
319         "static int stackwrite;",
320         "static int stackread;",
321         "static Trail frameptr;",
322         "Trail *",
323         "getframe(long d)",
324         "{",
325         "       if (CNT1 == CNT2)",
326         "               return &trail[d];",
327         "",
328         "       if (d >= (CNT1-CNT2)*DDD)",
329         "               return &trail[d - (CNT1-CNT2)*DDD];",
330         "",
331         "       if (!stackread",
332         "       &&  (stackread = open(stackfile, 0)) < 0)",
333         "       {       printf(\"getframe: cannot open %%s\\n\", stackfile);",
334         "               wrapup();",
335         "       }",
336         "       if (lseek(stackread, d* (off_t) sizeof(Trail), SEEK_SET) == -1",
337         "       || read(stackread, &frameptr, sizeof(Trail)) != sizeof(Trail))",
338         "       {       printf(\"getframe: frame read error\\n\");",
339         "               wrapup();",
340         "       }",
341         "       return &frameptr;",
342         "}",
343         "#endif",
344         "#if NCORE>1",
345         "extern void cleanup_shm(int);",
346         "volatile uint  *search_terminated; /* to signal early termination */",
347         /*
348          *      Meaning of bitflags in search_terminated:
349          *        1     set by pan_exit
350          *        2     set by wrapup
351          *        4     set by uerror
352          *        8     set by sudden_stop -- called after someone_crashed and [Uu]error
353          *       16     set by cleanup_shm
354          *       32     set by give_up  -- called on signal
355          *       64     set by proxy_exit
356          *      128     set by proxy on write port failure
357          *      256     set by proxy on someone_crashed
358          *
359          *      Flags 8|32|128|256 indicate abnormal termination
360          *
361          *      The flags are checked in 4 functions in the code:
362          *              sudden_stop()
363          *              someone_crashed() (proxy and pan version)
364          *              mem_hand_off()
365          */
366         "#endif",
367         "void",
368         "pan_exit(int val)",
369         "{      void stop_timer(int);",
370         "#ifdef BFS_PAR",
371         "       extern void bfs_mark_done(int);",
372         "       extern void bfs_drop_shared_memory(void);",
373         "#endif",
374         "       if (signoff)",
375         "       {       printf(\"--end of output--\\n\");",
376         "       }",
377         "#if NCORE>1",
378         "       if (search_terminated != NULL)",
379         "       {       *search_terminated |= 1;        /* pan_exit */",
380         "       }",
381                 "#ifdef USE_DISK",
382         "       { void  dsk_stats(void);",
383         "               dsk_stats();",
384         "       }",
385                 "#endif",
386         "       if (!state_tables && !readtrail)",
387         "       {       cleanup_shm(1);",
388         "       }",
389         "#endif",
390         "#ifdef BFS_PAR",
391         "       if (who_am_i != 0)",
392         "       {       bfs_mark_done(3); /* stopped */",
393         "       }",
394         "       bfs_drop_shared_memory();",
395         "#endif",
396         "       if (val == 2)",
397         "       {       val = 0;",
398         "       }",
399         "#ifdef BFS_PAR",
400         "       if (who_am_i == 0)",
401         "#endif",
402         "       stop_timer(1);",
403         "",
404         "#ifdef C_EXIT",
405         "       C_EXIT; /* trust that it defines a fct */",
406         "#endif",
407         "       exit(val);",
408         "}",
409         "#ifdef HAS_CODE",
410         "static char tbuf[2][2048];",
411         "",
412         "char *",
413         "transmognify(char *s)",
414         "{      char *v, *w;",
415         "       int i, toggle = 0;",
416         "       if (!s || strlen(s) > 2047) return s;",
417         "       memset(tbuf[0], 0, 2048);",
418         "       memset(tbuf[1], 0, 2048);",
419         "       strcpy(tbuf[toggle], s);",
420         "       while ((v = strstr(tbuf[toggle], \"{c_code\")))",       /* assign v */
421         "       {       *v = '\\0'; v++;",
422         "               strcpy(tbuf[1-toggle], tbuf[toggle]);",
423         "               for (w = v; *w != '}' && *w != '\\0'; w++) /* skip */;",
424         "               if (*w != '}') return s;",
425         "               *w = '\\0'; w++;",
426         "               for (i = 0; code_lookup[i].c; i++)",
427         "                       if (strcmp(v, code_lookup[i].c) == 0",
428         "                       &&  strlen(v) == strlen(code_lookup[i].c))",
429         "                       {       if (strlen(tbuf[1-toggle])",
430         "                                +  strlen(code_lookup[i].t)",
431         "                                +  strlen(w) > 2047)",
432         "                                       return s;",
433         "                               strcat(tbuf[1-toggle], code_lookup[i].t);",
434         "                               break;",
435         "                       }",
436         "               strcat(tbuf[1-toggle], w);",
437         "               toggle = 1 - toggle;",
438         "       }",
439         "       tbuf[toggle][2047] = '\\0';",
440         "       return tbuf[toggle];",
441         "}",
442         "#else",
443         "char * transmognify(char *s) { return s; }",
444         "#endif",
445
446         "#ifdef HAS_CODE",
447         "void",
448         "add_src_txt(int ot, int tt)",
449         "{      Trans *t;",
450         "       char *q;",
451         "",
452         "       for (t = trans[ot][tt]; t; t = t->nxt)",
453         "       {       printf(\"\\t\\t\");",
454         "               q = transmognify(t->tp);",
455         "               for ( ; q && *q; q++)",
456         "                       if (*q == '\\n')",
457         "                               printf(\"\\\\n\");",
458         "                       else",
459         "                               putchar(*q);",
460         "               printf(\"\\n\");",
461         "       }",
462         "}",
463         "",
464         "char *",
465         "find_source(int tp, int s)",
466         "{",
467         "       if (s >= flref[tp]->from",
468         "       &&  s <= flref[tp]->upto)",
469         "       {       return flref[tp]->fnm;",
470         "       }",
471         "       return PanSource; /* i.e., don't know */",
472         "}",
473         "",
474         "void",
475         "wrap_trail(void)",
476         "{      static int wrap_in_progress = 0;",
477         "       int i; short II;",
478         "       P0 *z;",
479         "",
480         "       if (wrap_in_progress++) return;",
481         "",
482         "       printf(\"spin: trail ends after %%ld steps\\n\", depth);",
483         "       if (onlyproc >= 0)",
484         "       {       if (onlyproc >= now._nr_pr) { pan_exit(0); }",
485         "               II = onlyproc;",
486         "               z = (P0 *)pptr(II);",
487         "               printf(\"%%3ld:\tproc %%d (%%s) \",",
488         "                       depth, II, procname[z->_t]);",
489         "               for (i = 0; src_all[i].src; i++)",
490         "                       if (src_all[i].tp == (int) z->_t)",
491         "                       {       printf(\" %%s:%%d\",",
492         "                                       find_source((int) z->_t, (int) z->_p),",
493         "                                       src_all[i].src[z->_p]);",
494         "                               break;",
495         "                       }",
496         "               printf(\" (state %%2d)\", z->_p);",
497         "               if (!stopstate[z->_t][z->_p])",
498         "                       printf(\" (invalid end state)\");",
499         "               printf(\"\\n\");",
500         "               add_src_txt(z->_t, z->_p);",
501         "               pan_exit(0);",
502         "       }",
503         "       printf(\"#processes %%d:\\n\", now._nr_pr);",
504         "       if (depth < 0) depth = 0;",
505         "       for (II = 0; II < now._nr_pr; II++)",
506         "       {       z = (P0 *)pptr(II);",
507         "               printf(\"%%3ld:\tproc %%d (%%s) \",",
508         "                       depth, II, procname[z->_t]);",
509         "               for (i = 0; src_all[i].src; i++)",
510         "                       if (src_all[i].tp == (int) z->_t)",
511         "                       {       printf(\" %%s:%%d\",",
512         "                                       find_source((int) z->_t, (int) z->_p),",
513         "                                       src_all[i].src[z->_p]);",
514         "                               break;",
515         "                       }",
516         "               printf(\" (state %%2d)\", z->_p);",
517         "               if (!stopstate[z->_t][z->_p])",
518         "                       printf(\" (invalid end state)\");",
519         "               printf(\"\\n\");",
520         "               add_src_txt(z->_t, z->_p);",
521         "       }",
522         "       c_globals();",
523         "       for (II = 0; II < now._nr_pr; II++)",
524         "       {       z = (P0 *)pptr(II);",
525         "               c_locals(II, z->_t);",
526         "       }",
527         "#ifdef ON_EXIT",
528         "       ON_EXIT;",
529         "#endif",
530         "       pan_exit(0);",
531         "}",
532         "FILE *",
533         "findtrail(void)",
534         "{      FILE *fd;",
535         "       char fnm[512], *q;",
536         "       char MyFile[512];",     /* avoid using a non-writable string */
537         "       char MySuffix[16];",
538         "       int  try_core;",
539         "       int  candidate_files;",
540         "",
541         "       if (trailfilename != NULL)",
542         "       {       fd = fopen(trailfilename, \"r\");",
543         "               if (fd == NULL)",
544         "               {       printf(\"pan: cannot find %%s\\n\", trailfilename);",
545         "                       pan_exit(1);",
546         "               } /* else */",
547         "               goto success;",
548         "       }",
549         "talk:",
550         "       try_core = 1;",
551         "       candidate_files = 0;",
552         "       tprefix = \"trail\";",
553         "       strcpy(MyFile, TrailFile);",
554         "       do { /* see if there's more than one possible trailfile */",
555         "               if (whichtrail)",
556         "               {       sprintf(fnm, \"%%s%%d.%%s\",",
557         "                               MyFile, whichtrail, tprefix);",
558         "                       fd = fopen(fnm, \"r\");",
559         "                       if (fd != NULL)",
560         "                       {       candidate_files++;",
561         "                               if (verbose==100)",
562         "                                       printf(\"trail%%d: %%s\\n\",",
563         "                                               candidate_files, fnm);",
564         "                               fclose(fd);",
565         "                       }",
566         "                       if ((q = strchr(MyFile, \'.\')) != NULL)",
567         "                       {       *q = \'\\0\';", /* e.g., strip .pml */
568         "                               sprintf(fnm, \"%%s%%d.%%s\",",
569         "                                       MyFile, whichtrail, tprefix);",
570         "                               *q = \'.\';",
571         "                               fd = fopen(fnm, \"r\");",
572         "                               if (fd != NULL)",
573         "                               {       candidate_files++;",
574         "                                       if (verbose==100)",
575         "                                               printf(\"trail%%d: %%s\\n\",",
576         "                                                       candidate_files, fnm);",
577         "                                       fclose(fd);",
578         "                       }       }",
579         "               } else",
580         "               {       sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
581         "                       fd = fopen(fnm, \"r\");",
582         "                       if (fd != NULL)",
583         "                       {       candidate_files++;",
584         "                               if (verbose==100)",
585         "                                       printf(\"trail%%d: %%s\\n\",",
586         "                                               candidate_files, fnm);",
587         "                               fclose(fd);",
588         "                       }",
589         "                       if ((q = strchr(MyFile, \'.\')) != NULL)",
590         "                       {       *q = \'\\0\';", /* e.g., strip .pml */
591         "                               sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
592         "                               *q = \'.\';",
593         "                               fd = fopen(fnm, \"r\");",
594         "                               if (fd != NULL)",
595         "                               {       candidate_files++;",
596         "                                       if (verbose==100)",
597         "                                               printf(\"trail%%d: %%s\\n\",",
598         "                                                       candidate_files, fnm);",
599         "                                       fclose(fd);",
600         "               }       }       }",
601         "               tprefix = MySuffix;",
602         "               sprintf(tprefix, \"cpu%%d_trail\", try_core++);",
603         "       } while (try_core <= NCORE);",
604         "",
605         "       if (candidate_files != 1)",
606         "       {       if (verbose != 100)",
607         "               {       printf(\"error: there are %%d trail files:\\n\",",
608         "                               candidate_files);",
609         "                       verbose = 100;",
610         "                       goto talk;",
611         "               } else",
612         "               {       printf(\"pan: rm or mv all except one\\n\");",
613         "                       exit(1);",
614         "       }       }",
615
616         "       try_core = 1;",
617         "       strcpy(MyFile, TrailFile); /* restore */",
618         "       tprefix = \"trail\";",
619         "try_again:",
620         "       if (whichtrail)",
621         "       {       sprintf(fnm, \"%%s%%d.%%s\", MyFile, whichtrail, tprefix);",
622         "               fd = fopen(fnm, \"r\");",
623         "               if (fd == NULL && (q = strchr(MyFile, \'.\')))",
624         "               {       *q = \'\\0\';", /* e.g., strip .pml on original file */
625         "                       sprintf(fnm, \"%%s%%d.%%s\",",
626         "                               MyFile, whichtrail, tprefix);",
627         "                       *q = \'.\';",
628         "                       fd = fopen(fnm, \"r\");",
629         "               }",
630         "       } else",
631         "       {       sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
632         "               fd = fopen(fnm, \"r\");",
633         "               if (fd == NULL && (q = strchr(MyFile, \'.\')))",
634         "               {       *q = \'\\0\';", /* e.g., strip .pml on original file */
635         "                       sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
636         "                       *q = \'.\';",
637         "                       fd = fopen(fnm, \"r\");",
638         "       }       }",
639         "       if (fd == NULL)",
640         "       {       if (try_core < NCORE)",
641         "               {       tprefix = MySuffix;",
642         "                       sprintf(tprefix, \"cpu%%d_trail\", try_core++);",
643         "                       goto try_again;",
644         "               }",
645         "               printf(\"pan: cannot find trailfile %%s\\n\", fnm);",
646         "               pan_exit(1);",
647         "       }",
648         "success:",
649         "#if NCORE>1 && defined(SEP_STATE)",
650         "       {       void set_root(void); /* for partial traces from local root */",
651         "               set_root();",
652         "       }",
653         "#endif",
654         "       return fd;",
655         "}",
656         "",
657         "uchar do_transit(Trans *, short);",
658         "#ifdef PERMUTED",
659         "void set_permuted(int);",
660         "void set_reversed(int);",
661         "void set_rotated(int);",
662         "void set_randrot(int);",
663         "void (*p_reorder)(int) = set_permuted;",
664         "short p_rotate;",
665         "#endif",
666         "",
667         "void",
668         "getrail(void)",
669         "{      FILE *fd;",
670         "       char *q, *pnm;",
671         "       int i, t_id, lastnever = -1; short II;",
672         "       Trans *t;",
673         "       P0 *z;",
674         "#ifdef PERMUTED",
675         "       char sbuf[128];",
676         "       memset(sbuf, 0, sizeof(sbuf));",
677         "#endif",
678         "       fd = findtrail();       /* exits if unsuccessful */",
679         "       while (fscanf(fd, \"%%ld:%%d:%%d\\n\", &depth, &i, &t_id) == 3)",
680         "       {       if (depth == -1)",
681         "               {       printf(\"<<<<<START OF CYCLE>>>>>\\n\");",
682         "               }",
683         "#ifdef PERMUTED",
684         "               if (depth < 0)",
685         "               {       switch (depth) {",
686         "                       case -5:",
687         "                               if (i && !t_reverse)",
688         "                               {       strcat(sbuf, \"-t_reverse \");",
689         "                               }",
690         "                               break;",
691         "                       case -6:",
692         "                               if (i && p_reorder != set_permuted)",
693         "                               {       strcat(sbuf, \"-p_permute \");",
694         "                               } else",
695         "                               if (t_id && p_reorder != set_reversed)",
696         "                               {       strcat(sbuf, \"-p_reverse \");",
697         "                               }",
698         "                               break;",
699         "                       case -7:",
700         "                               if (i",
701         "                               && (p_reorder != set_rotated || p_rotate != t_id))",
702         "                               {       char tmp[32];",
703         "                                       sprintf(tmp, \"-p_rotate%%d \", t_id);",
704         "                                       strcat(sbuf, tmp);",
705         "                               }",
706         "                               break;",
707         "                       case -8:",
708         "                               if (i && p_reorder != set_randrot)",
709         "                               {       strcat(sbuf, \"-p_randrot \");",
710         "                               }",
711         "                               if (s_rand != ++t_id)",
712         "                               {       char tmp[32];",
713         "                                       sprintf(tmp, \"-RS%%u \", (uint) t_id-1);",
714         "                                       strcat(sbuf, tmp);",
715         "                               }",
716         "                               break;",
717         "                       default:",
718         "                               continue;",
719         "                       }",
720         "               }",
721         "#endif",
722         "               if (depth < 0)",
723         "               {       continue;",
724         "               }",
725         "#ifdef PERMUTED",
726         "               if (strlen(sbuf) > 0)",
727         "               {       fprintf(efd, \"add: %%s\\n\", sbuf);",
728         "                       exit(1);",
729         "               }",
730         "#endif",
731         "               if (i > now._nr_pr)",
732         "               {       printf(\"pan: Error, proc %%d invalid pid \", i);",
733         "                       printf(\"transition %%d\\n\", t_id);",
734         "                       break;",
735         "               }",
736         "               II = i;",
737         "               z = (P0 *)pptr(II);",
738         "               for (t = trans[z->_t][z->_p]; t; t = t->nxt)",
739         "                       if (t->t_id == (T_ID) t_id)",
740         "                               break;",
741         "               if (!t)",
742         "               {       for (i = 0; i < NrStates[z->_t]; i++)",
743         "                       {       t = trans[z->_t][i];",
744         "                               if (t && t->t_id == (T_ID) t_id)",
745         "                               {       printf(\"\\tRecovered at state %%d\\n\", i);",
746         "                                       z->_p = i;",
747         "                                       goto recovered;",
748         "                       }       }",
749         "                       printf(\"pan: Error, proc %%d type %%d state %%d: \",",
750         "                               II, z->_t, z->_p);",
751         "                       printf(\"transition %%d not found\\n\", t_id);",
752         "                       printf(\"pan: list of possible transitions in this process:\\n\");",
753         "                       if (z->_t >= 0 && z->_t <= _NP_)",
754         "                       for (t = trans[z->_t][z->_p]; t; t = t->nxt)",
755         "                               printf(\"       t_id %%d -- case %%d, [%%s]\\n\",",
756         "                                       t->t_id, t->forw, t->tp);",
757         "                       break; /* pan_exit(1); */",
758         "               }",
759         "recovered:",
760         "               q = transmognify(t->tp);",
761         "               if (gui) simvals[0] = \'\\0\';",
762
763         "               pnm = procname[z->_t];",
764         "               this = pptr(II);",
765         "               trpt->tau |= 1;",       /* timeout always possible */
766         "               if (!do_transit(t, II))",
767         "               {       if (onlyproc >= 0 && II != onlyproc)",
768         "                               goto moveon;",
769         "                       if (!verbose) break;",
770         "                       printf(\"pan: error, next transition UNEXECUTABLE on replay\\n\");",
771         "                       printf(\"     most likely causes: missing c_track statements\\n\");",
772         "                       printf(\"       or illegal side-effects in c_expr statements\\n\");",
773         "               }",
774
775         "               if (onlyproc >= 0 && II != onlyproc)",
776         "                       goto moveon;",
777
778         "               if (verbose)",
779         "               {       printf(\"%%3ld: proc %%2d (%%s) \", depth, II, pnm);",
780
781         "                       for (i = 0; src_all[i].src; i++)",
782         "                               if (src_all[i].tp == (int) z->_t)",
783         "                               {       printf(\" %%s:%%d \",",
784         "                                               find_source((int) z->_t, (int) z->_p),",
785         "                                               src_all[i].src[z->_p]);",
786         "                                       break;",
787         "                               }",
788
789         "                       printf(\"(state %%d) trans {%%d,%%d} [%%s]\\n\",",
790         "                               z->_p, t_id, t->forw, q?q:\"\");",
791
792         "                       c_globals();",
793         "                       for (i = 0; i < now._nr_pr; i++)",
794         "                       {       c_locals(i, ((P0 *)pptr(i))->_t);",
795         "                       }",
796         "               } else if (Btypes[z->_t] == N_CLAIM)",
797         "               {       if (lastnever != (int) z->_p)",
798         "                       {       for (i = 0; src_all[i].src; i++)",
799         "                                       if (src_all[i].tp == (int) z->_t)",
800         "                                       {       printf(\"MSC: ~G %%d\\n\",",
801         "                                                       src_all[i].src[z->_p]);",
802         "                                               break;",
803         "                                       }",
804         "                               if (!src_all[i].src)",
805         "                                       printf(\"MSC: ~R %%d\\n\", z->_p);",
806         "                       }",
807         "                       lastnever = z->_p;",
808         "                       goto sameas;",
809         "               } else if (Btypes[z->_t] != 0) /* not :np_: */",
810         "               {",
811         "sameas:                if (no_rck) goto moveon;",
812         "                       if (coltrace)",
813         "                       {       printf(\"%%ld: \", depth);",
814         "                               for (i = 0; i < II; i++)",
815         "                                       printf(\"\\t\\t\");",
816         "                               printf(\"%%s(%%d):\", pnm, II);",
817         "                               printf(\"[%%s]\\n\", q?q:\"\");",
818         "                       } else if (!silent)",
819         "                       {       if (strlen(simvals) > 0) {",
820         "                               printf(\"%%3ld: proc %%2d (%%s)\", ",
821         "                                       depth, II, pnm);",
822         "                               for (i = 0; src_all[i].src; i++)",
823         "                                       if (src_all[i].tp == (int) z->_t)",
824         "                                       {       printf(\" %%s:%%d \",",
825         "                                                       find_source((int) z->_t, (int) z->_p),",
826         "                                                       src_all[i].src[z->_p]);",
827         "                                               break;",
828         "                                       }",
829         "                               printf(\"(state %%d)\t[values: %%s]\\n\", z->_p, simvals);",
830         "                               }",
831         "                               printf(\"%%3ld: proc %%2d (%%s)\", ",
832         "                                       depth, II, pnm);",
833         "                               for (i = 0; src_all[i].src; i++)",
834         "                                       if (src_all[i].tp == (int) z->_t)",
835         "                                       {       printf(\" %%s:%%d \",",
836         "                                                       find_source((int) z->_t, (int) z->_p),",
837         "                                                       src_all[i].src[z->_p]);",
838         "                                               break;",
839         "                                       }",
840         "                               printf(\"(state %%d)\t[%%s]\\n\", z->_p, q?q:\"\");",
841         "                       /*      printf(\"\\n\");        */",
842         "               }       }",
843         "moveon:        z->_p = t->st;",
844         "       }",
845         "       wrap_trail();",
846         "}",
847         "#endif",
848         "int",
849         "f_pid(int pt)",
850         "{      int i;",
851         "       P0 *z;",
852         "       for (i = 0; i < now._nr_pr; i++)",
853         "       {       z = (P0 *)pptr(i);",
854         "               if (z->_t == (unsigned) pt)",
855         "                       return BASE+z->_pid;",
856         "       }",
857         "       return -1;",
858         "}",
859         "",
860         "#if NCORE>1 && !defined(GLOB_HEAP)",
861         "       #define SEP_HEAP /* version 5.1.2 */",
862         "#endif",
863         "",
864         "#ifdef BITSTATE",
865         "int",
866         "bstore_mod(char *v, int n)     /* hasharray size not a power of two */",
867         "{      ulong x, y;",
868         "       uint i = 1;",
869         "#if defined(MURMUR) && (WS==8)",
870         "       m_hash((uchar *) v, n); /* bstore_mod - sets j3_spin, j4_spin, K1, K2 */",
871         "#else",
872         "       d_hash((uchar *) v, n); /* bstore_mod - sets j3_spin, j4_spin, K1, K2 */",
873         "#endif",
874         "       x = K1; y = j3_spin;",  /* was K2 before 5.1.1 */
875         "       for (;;)",
876         "       {       if (!(SS[x%%udmem]&(1<<y))) break;",    /* take the hit in speed */
877         "               if (i == hfns) {",
878                                 "#ifdef DEBUG",
879         "                       printf(\"Old bitstate\\n\");",
880                                 "#endif",
881         "                       return 1;",
882         "               }",
883         "               x = (x + K2 + i);",     /* no mask, using mod - was K1 before 5.1.1 */
884         "               y = (y + j4_spin) & 7;",
885         "               i++;",
886         "       }",
887                 "#ifdef RANDSTOR",
888         "       if (rand()%%100 > RANDSTOR) return 0;",
889                 "#endif",
890         "       for (;;)",
891         "       {       SS[x%%udmem] |= (1<<y);",
892         "               if (i == hfns) break;", /* done */
893         "               x = (x + K2 + i);",     /* no mask - was K1 before 5.1.1 */
894         "               y = (y + j4_spin) & 7;",
895         "               i++;",
896         "       }",
897                 "#ifdef DEBUG",
898         "       printf(\"New bitstate\\n\");",
899                 "#endif",
900         "       if (now._a_t&1)",
901         "       {       nShadow++;",
902         "       }",
903         "       return 0;",
904         "}",
905         "int",
906         "bstore_reg(char *v, int n)     /* extended hashing, Peter Dillinger, 2004 */",
907         "{      ulong x, y;",
908         "       uint i = 1;",
909         "#if defined(MURMUR) && (WS==8)",
910         "       m_hash((uchar *) v, n); /* bstore_reg - sets j1_spin-j4_spin */",
911         "#else",
912         "       d_hash((uchar *) v, n); /* bstore_reg - sets j1_spin-j4_spin */",
913         "#endif",
914         "       x = j2_spin; y = j3_spin;",
915         "       for (;;)",
916         "       {       if (!(SS[x]&(1<<y))) break;",   /* at least one bit not set */
917         "               if (i == hfns) {",
918                                 "#ifdef DEBUG",
919         "                       printf(\"Old bitstate\\n\");",
920                                 "#endif",
921         "                       return 1;",
922         "               }",
923         "               x = (x + j1_spin + i) & nmask;",
924         "               y = (y + j4_spin) & 7;",
925         "               i++;",
926         "       }",
927                 "#ifdef RANDSTOR",
928         "       if (rand()%%100 > RANDSTOR) return 0;",
929                 "#endif",
930         "       for (;;)",
931         "       {       SS[x] |= (1<<y);",
932         "               if (i == hfns) break;",         /* done */
933         "               x = (x + j1_spin + i) & nmask;",
934         "               y = (y + j4_spin) & 7;",
935         "               i++;",
936         "       }",
937                 "#ifdef DEBUG",
938         "       printf(\"New bitstate\\n\");",
939                 "#endif",
940         "       if (now._a_t&1)",
941         "       {       nShadow++;",
942         "       }",
943         "       return 0;",
944         "}",
945         "#endif", /* BITSTATE */
946         "ulong TMODE = 0666; /* file permission bits for trail files */",
947         "",
948         "int trcnt=1;",
949         "char snap[64], fnm[512];",
950         "",
951         "int",
952         "make_trail(void)",
953         "{      int fd;",
954         "       char *q;",
955         "       char MyFile[512];",
956         "       int w_flags = O_CREAT|O_WRONLY|O_TRUNC;",
957         "",
958         "       if (exclusive == 1 && iterative == 0)",
959         "       {       w_flags |= O_EXCL;",
960         "       }",
961         "",
962         "       q = strrchr(TrailFile, \'/\');",
963         "       if (q == NULL) q = TrailFile; else q++;",
964         "       strcpy(MyFile, q); /* TrailFile is not a writable string */",
965         "",
966         "       if (iterative == 0 && Nr_Trails++ > 0)",
967         "       {",
968         "#ifdef PUTPID",
969         "               sprintf(fnm, \"%%s_%%s_%%d_%%d.%%s\",",
970         "                       MyFile, progname, getpid(), Nr_Trails-1, tprefix);",
971         "#else",
972         "               sprintf(fnm, \"%%s%%d.%%s\",",
973         "                       MyFile, Nr_Trails-1, tprefix);",
974         "#endif",
975         "       } else",
976         "       {",
977         "#ifdef PUTPID",
978         "               sprintf(fnm, \"%%s_%%s_%%d.%%s\", MyFile, progname, getpid(), tprefix);",
979         "#else",
980         "               sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
981         "#endif",
982         "       }",
983         "       if ((fd = open(fnm, w_flags, TMODE)) < 0)",
984         "       {       if ((q = strchr(MyFile, \'.\')))",
985         "               {       *q = \'\\0\';",         /* strip .pml */
986         "                       if (iterative == 0 && Nr_Trails-1 > 0)",
987         "                               sprintf(fnm, \"%%s%%d.%%s\",",
988         "                                       MyFile, Nr_Trails-1, tprefix);",
989         "                       else",
990         "                               sprintf(fnm, \"%%s.%%s\", MyFile, tprefix);",
991         "                       *q = \'.\';",
992         "                       fd = open(fnm, w_flags, TMODE);",
993         "       }       }",
994         "       if (fd < 0)",
995         "       {       printf(\"pan: cannot create %%s\\n\", fnm);",
996         "               perror(\"cause\");",
997         "       } else",
998         "       {",
999         "#if NCORE>1 && (defined(SEP_STATE) || !defined(FULL_TRAIL))",
1000         "       void write_root(void); ",
1001         "       write_root();",
1002         "#else",
1003         "               printf(\"pan: wrote %%s\\n\", fnm);",
1004         "#endif",
1005         "       }",
1006         "       return fd;",
1007         "}",
1008         "",
1009         "#ifndef FREQ",
1010         "#define FREQ   (1000000)",
1011         "#endif",
1012         "double freq = (double) FREQ;\n",
1013
1014         "#ifdef TRIX",
1015         "void sv_populate(void);",
1016         "",
1017         "void",
1018         "re_populate(void) /* restore procs and chans from now._ids_ */",
1019         "{      int i, cnt = 0;",
1020         "       char *b;",
1021         "#ifdef V_TRIX",
1022         "       printf(\"%%4d: re_populate\\n\", depth);",
1023         "#endif",
1024         "       for (i = 0; i < now._nr_pr; i++, cnt++)",
1025         "       {       b = now._ids_[cnt];",
1026         "               processes[i]->psize = what_p_size( ((P0 *)b)->_t );",
1027         "               memcpy(processes[i]->body, b, processes[i]->psize);",
1028         "#ifdef TRIX_RIX",
1029         "               ((P0 *)pptr(i))->_pid = i;",
1030         "               if (BASE > 0 && h > 0)",
1031         "               {       ((P0 *)pptr(i))->_pid -= BASE;",
1032         "               }",
1033         "#endif",
1034         "#ifndef BFS",
1035         "               processes[i]->modified = 1; /* re-populate */",
1036         "#endif",
1037         "       }",
1038         "       for (i = 0; i < now._nr_qs; i++, cnt++)",
1039         "       {       b = now._ids_[cnt];",
1040         "               channels[i]->psize = what_q_size( ((Q0 *)b)->_t );",
1041         "               memcpy(channels[i]->body, b, channels[i]->psize);",
1042         "#ifndef BFS",
1043         "               channels[i]->modified = 1; /* re-populate */",
1044         "#endif",
1045         "       }",
1046         "}",
1047         "#endif\n",
1048
1049         "#ifdef BFS",   /* breadth-first search */
1050         "       #ifndef BFS_PAR",
1051         "               BFS_State *bfs_trail, *bfs_bot, *bfs_free;",
1052         "               SV_Hold *svfree;",
1053         "       #else",
1054         "               static ulong    bfs_pre_allocated;",
1055         "       #endif",
1056         "       #ifdef BFS_DISK",
1057         "               #ifndef BFS_LIMIT",
1058         "                       #define BFS_LIMIT       100000",
1059         "               #endif",
1060         "               #ifndef BFS_DSK_LIMIT",
1061         "                       #define BFS_DSK_LIMIT   1000000",
1062         "               #endif",
1063         "               #if defined(WIN32) || defined(WIN64)",
1064         "                       #define RFLAGS  (O_RDONLY|O_BINARY)",
1065         "                       #define WFLAGS  (O_CREAT|O_WRONLY|O_TRUNC|O_BINARY)",
1066         "                       #define RWFLAGS (O_RDWR|O_BINARY)",
1067         "               #else",
1068         "                       #define RFLAGS  (O_RDONLY)",
1069         "                       #define WFLAGS  (O_CREAT|O_WRONLY|O_TRUNC)",
1070         "                       #define RWFLAGS (O_RDWR)",
1071         "               #endif",
1072         "",
1073         "               long bfs_size_limit;",
1074         "               int bfs_dsk_write = -1;",
1075         "               int bfs_dsk_read = -1;",
1076         "               long bfs_dsk_writes, bfs_dsk_reads;",
1077         "               int bfs_dsk_seqno_w, bfs_dsk_seqno_r;",
1078         "       #endif",
1079         "",
1080         "uchar do_reverse(Trans *, short, uchar);",
1081         "void snapshot(void);",
1082         "#if 0",
1083         "void",
1084         "select_claim(int x)    /* ignored in BFS mode */",
1085         "{      if (verbose)",
1086         "       {       printf(\"select %%d (ignored)\\n\", x);",
1087         "       }",
1088         "}",
1089         "#endif",
1090         "Trail *ntrpt;",
1091         "",
1092         "#ifndef BFS_PAR",
1093         "SV_Hold *",
1094         "getsv(int n)",
1095         "{      SV_Hold *h;",
1096         "",
1097         "       if (svfree && n <= svfree->sz)",
1098         "       {       h = svfree;",
1099         "               svfree = h->nxt;",
1100         "               h->nxt = (SV_Hold *) 0;",
1101         "       } else",
1102         "       {       h = (SV_Hold *) emalloc(sizeof(SV_Hold));",
1103         "               h->sz = n;",
1104         "       #ifdef BFS_DISK",
1105         "               if (bfs_size_limit >= BFS_LIMIT)",
1106         "               {       h->sv = (State *) 0;    /* means: read disk */",
1107         "                       bfs_dsk_writes++;       /* count */",
1108         "                       if (bfs_dsk_write < 0   /* file descriptor */",
1109         "                       ||  bfs_dsk_writes%%BFS_DSK_LIMIT == 0)",
1110         "                       {       char dsk_nm[32];",
1111         "                               if (bfs_dsk_write >= 0)",
1112         "                               {       (void) close(bfs_dsk_write);",
1113         "                               }",
1114         "                               sprintf(dsk_nm, \"pan_bfs_%%d.tmp\", bfs_dsk_seqno_w++);",
1115         "                               bfs_dsk_write = open(dsk_nm, WFLAGS, 0644);",
1116         "                               if (bfs_dsk_write < 0)",
1117         "                               {       Uerror(\"could not create tmp disk file\");",
1118         "                               }",
1119         "                               printf(\"pan: created disk file %%s\\n\", dsk_nm);",
1120         "                       }",
1121         "                       if (write(bfs_dsk_write, (char *) &now, n) != n)",
1122         "                       {       Uerror(\"aborting -- disk write failed (disk full?)\");",
1123         "                       }",
1124         "                       return h; /* no memcpy */",
1125         "               }", /* else */
1126         "               bfs_size_limit++;",
1127         "       #endif",
1128         "               h->sv = (State *) emalloc(sizeof(State) - VECTORSZ + n);",
1129         "       }",
1130         "",
1131         "       memcpy((char *)h->sv, (char *)&now, n);",
1132         "       return h;",
1133         "}",
1134         "",
1135         "EV_Hold *",
1136         "getsv_mask(int n)",
1137         "{      EV_Hold *h;",
1138         "       static EV_Hold *kept = (EV_Hold *) 0;",
1139         "",
1140         "       for (h = kept; h; h = h->nxt)",
1141         "               if (n == h->sz",
1142         "#if !defined(NOCOMP) && !defined(HC)",
1143         "               &&  (memcmp((char *) Mask, (char *) h->sv, n) == 0)",
1144         "#endif",
1145         "               &&  (now._nr_pr == h->nrpr)",
1146         "               &&  (now._nr_qs == h->nrqs)",
1147         "       #ifdef TRIX",
1148         "               )",
1149         "       #else",
1150         "               #if VECTORSZ>32000",
1151         "               &&  (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(int)) == 0)",
1152         "               &&  (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(int)) == 0)",
1153         "               #else",
1154         "               &&  (memcmp((char *) proc_offset, (char *) h->po, now._nr_pr * sizeof(short)) == 0)",
1155         "               &&  (memcmp((char *) q_offset, (char *) h->qo, now._nr_qs * sizeof(short)) == 0)",
1156         "               #endif",
1157         "               &&  (memcmp((char *) proc_skip, (char *) h->ps, now._nr_pr * sizeof(uchar)) == 0)",
1158         "               &&  (memcmp((char *) q_skip,    (char *) h->qs, now._nr_qs * sizeof(uchar)) == 0))",
1159         "       #endif",
1160         "                       break;",
1161         "       if (!h)",
1162         "       {       h = (EV_Hold *) emalloc(sizeof(EV_Hold));",
1163         "               h->sz = n;",
1164         "               h->nrpr = now._nr_pr;",
1165         "               h->nrqs = now._nr_qs;",
1166         "",
1167         "               h->sv = (char *) emalloc(n * sizeof(char));",
1168         "#if !defined(NOCOMP) && !defined(HC)",
1169         "               memcpy((char *) h->sv, (char *) Mask, n);",
1170         "#endif",
1171         "       #ifndef TRIX",
1172         "               if (now._nr_pr > 0)",
1173         "               {       h->ps = (char *) emalloc(now._nr_pr * sizeof(int));",
1174         "                       memcpy((char *) h->ps, (char *) proc_skip,   now._nr_pr * sizeof(uchar));",
1175         "               #if VECTORSZ>32000",
1176         "                       h->po = (char *) emalloc(now._nr_pr * sizeof(int));",
1177         "                       memcpy((char *) h->po, (char *) proc_offset, now._nr_pr * sizeof(int));",
1178         "               #else",
1179         "                       h->po = (char *) emalloc(now._nr_pr * sizeof(short));",
1180         "                       memcpy((char *) h->po, (char *) proc_offset, now._nr_pr * sizeof(short));",
1181         "               #endif",
1182         "               }",
1183         "               if (now._nr_qs > 0)",
1184         "               {       h->qs = (char *) emalloc(now._nr_qs * sizeof(int));",
1185         "                       memcpy((char *) h->qs, (char *) q_skip,   now._nr_qs * sizeof(uchar));",
1186         "               #if VECTORSZ>32000",
1187         "                       h->qo = (char *) emalloc(now._nr_qs * sizeof(int));",
1188         "                       memcpy((char *) h->qo, (char *) q_offset, now._nr_qs * sizeof(int));",
1189         "               #else",
1190         "                       h->qo = (char *) emalloc(now._nr_qs * sizeof(short));",
1191         "                       memcpy((char *) h->qo, (char *) q_offset, now._nr_qs * sizeof(short));",
1192         "               #endif",
1193         "               }",
1194         "       #endif",
1195         "               h->nxt = kept;",
1196         "               kept = h;",
1197         "       }",
1198         "       return h;",
1199         "}",
1200         "",
1201         "void",
1202         "freesv(SV_Hold *p)",
1203         "{      SV_Hold *h, *oh;",
1204         "",
1205         "       oh = (SV_Hold *) 0;",
1206         "       for (h = svfree; h; oh = h, h = h->nxt)",
1207         "       {       if (p->sz >= h->sz)",
1208         "                       break;",
1209         "       }",
1210         "       if (!oh)",
1211         "       {       p->nxt = svfree;",
1212         "               svfree = p;",
1213         "       } else",
1214         "       {       p->nxt = h;",
1215         "               oh->nxt = p;",
1216         "       }",
1217         "}",
1218         "",
1219         "BFS_State *",
1220         "get_bfs_frame(void)",
1221         "{      BFS_State *t;",
1222         "",
1223         "       if (bfs_free)",
1224         "       {       t = bfs_free;",
1225         "               bfs_free = bfs_free->nxt;",
1226         "               t->nxt = (BFS_State *) 0;",
1227         "       } else",
1228         "       {       t = (BFS_State *) emalloc(sizeof(BFS_State));",
1229         "       }",
1230         "       t->frame = (Trail *) emalloc(sizeof(Trail));", /* always new */
1231         "       /* new because we keep a ptr to the frame of parent states */",
1232         "       /* used for reconstructing path and recovering failed rvs etc */",
1233         "       return t;",
1234         "}",
1235         "",
1236         "void",
1237         "push_bfs(Trail *f, int d)",
1238         "{      BFS_State *t;",
1239         "",
1240         "       t = get_bfs_frame();",
1241         "       memcpy((char *)t->frame, (char *)f, sizeof(Trail));",
1242         "       t->frame->o_tt = d;     /* depth */",
1243         "",
1244         "       t->boq = boq;",
1245         "       #ifdef TRIX",
1246         "       sv_populate();",
1247         "       #endif",
1248         "       t->onow = getsv(vsize);",
1249         "       t->omask = getsv_mask(vsize);",
1250         "       #if defined(FULLSTACK) && defined(Q_PROVISO)",
1251         "       t->lstate = Lstate;     /* bfs */",
1252         "       #endif",
1253         "       if (!bfs_bot)",
1254         "       {       bfs_bot = bfs_trail = t;",
1255         "       } else",
1256         "       {       bfs_bot->nxt = t;",
1257         "               bfs_bot = t;",
1258         "       }",
1259         "       #ifdef VERBOSE",
1260         "       t->nr = nstates;",
1261         "       #endif",
1262         "       #ifdef CHECK",
1263         "               #ifdef VERBOSE",
1264         "       printf(\"PUSH %%lu (depth %%d, nr %%lu)\\n\", (ulong) t->frame, d, t->nr);",
1265         "               #else",
1266         "       printf(\"PUSH %%lu (depth %%d)\\n\", (ulong) t->frame, d);",
1267         "               #endif",
1268         "       #endif",
1269         "}",
1270         "",
1271         "Trail *",
1272         "pop_bfs(void)",
1273         "{      BFS_State *t;",
1274         "",
1275         "       if (!bfs_trail)",
1276         "       {       return (Trail *) 0;",
1277         "       }",
1278         "       t = bfs_trail;",
1279         "       bfs_trail = t->nxt;",
1280         "       if (!bfs_trail)",
1281         "       {       bfs_bot = (BFS_State *) 0;",
1282         "       }",
1283         "       #if defined(Q_PROVISO) && !defined(BITSTATE) && !defined(NOREDUCE)",
1284         "       if (t->lstate)                  /* bfs */",
1285         "       {       t->lstate->tagged = 0;  /* bfs */",
1286         "       }",
1287         "       #endif",
1288         "       t->nxt = bfs_free;",
1289         "       bfs_free = t;",
1290         "",
1291         "       vsize = t->onow->sz;",
1292         "       boq = t->boq;",
1293         "       #ifdef BFS_DISK",
1294         "       if (t->onow->sv == (State *) 0)",
1295         "       {       char dsk_nm[32];",
1296         "               bfs_dsk_reads++;        /* count */",
1297         "               if (bfs_dsk_read >= 0   /* file descriptor */",
1298         "               &&  bfs_dsk_reads%%BFS_DSK_LIMIT == 0)",
1299         "               {       (void) close(bfs_dsk_read);",
1300         "                       sprintf(dsk_nm, \"pan_bfs_%%d.tmp\", bfs_dsk_seqno_r-1);",
1301         "                       (void) unlink(dsk_nm);",
1302         "                       bfs_dsk_read = -1;",
1303         "               }",
1304         "               if (bfs_dsk_read < 0)",
1305         "               {       sprintf(dsk_nm, \"pan_bfs_%%d.tmp\", bfs_dsk_seqno_r++);",
1306         "                       bfs_dsk_read = open(dsk_nm, RFLAGS);",
1307         "                       if (bfs_dsk_read < 0)",
1308         "                       {       Uerror(\"could not open temp disk file\");",
1309         "               }       }",
1310         "               if (read(bfs_dsk_read, (char *) &now, vsize) != vsize)",
1311         "               {       Uerror(\"bad bfs disk file read\");",
1312         "               }",
1313         "               #ifndef NOVSZ",
1314         "               if (now._vsz != vsize)",
1315         "               {       Uerror(\"disk read vsz mismatch\");",
1316         "               }",
1317         "               #endif",
1318         "       } else",
1319         "       #endif",
1320         "       {       memcpy((uchar *) &now, (uchar *) t->onow->sv, vsize);",
1321         "       #ifndef NOVSZ",
1322         "               vsize = now._vsz;",
1323         "       #endif",
1324         "       }",
1325         "#if !defined(NOCOMP) && !defined(HC)",
1326         "       memcpy((uchar *) Mask, (uchar *) t->omask->sv, vsize);",
1327         "#endif",
1328         "       #ifdef TRIX",
1329         "       re_populate();",
1330         "       #else",
1331         "       if (now._nr_pr > 0)",
1332         "               #if VECTORSZ>32000",
1333         "       {       memcpy((char *)proc_offset, (char *)t->omask->po, now._nr_pr * sizeof(int));",
1334         "               #else",
1335         "       {       memcpy((char *)proc_offset, (char *)t->omask->po, now._nr_pr * sizeof(short));",
1336         "               #endif",
1337         "               memcpy((char *)proc_skip,   (char *)t->omask->ps, now._nr_pr * sizeof(uchar));",
1338         "       }",
1339         "       if (now._nr_qs > 0)",
1340         "               #if VECTORSZ>32000",
1341         "       {       memcpy((uchar *)q_offset, (uchar *)t->omask->qo, now._nr_qs * sizeof(int));",
1342         "               #else",
1343         "       {       memcpy((uchar *)q_offset, (uchar *)t->omask->qo, now._nr_qs * sizeof(short));",
1344         "               #endif",
1345         "               memcpy((uchar *)q_skip,   (uchar *)t->omask->qs, now._nr_qs * sizeof(uchar));",
1346         "       }",
1347         "       #endif",
1348         "       #ifdef BFS_DISK",
1349         "       if (t->onow->sv != (State *) 0)",
1350         "       #endif",
1351         "       {       freesv(t->onow);        /* omask not freed */",
1352         "       }",
1353         "       #ifdef CHECK",
1354         "               #ifdef VERBOSE",
1355         "       printf(\"POP %%lu (depth %%d, nr %%lu)\\n\", (ulong) t->frame, t->frame->o_tt, t->nr);",
1356         "               #else",
1357         "       printf(\"POP %%lu (depth %%d)\\n\", (ulong) t->frame, t->frame->o_tt);",
1358         "               #endif",
1359         "       #endif",
1360         "       return t->frame;",
1361         "}",
1362         "",
1363         "void",
1364         "store_state(Trail *ntrpt, int shortcut, short oboq)",
1365         "{",
1366         "       #ifdef VERI",
1367         "       Trans *t2 = (Trans *) 0;",
1368         "       uchar ot; int tt, E_state;",
1369         "       uchar o_opm = trpt->o_pm, *othis = this;",
1370         "",
1371         "       if (shortcut)",
1372         "       {",
1373         "               #ifdef VERBOSE",
1374         "               printf(\"claim: shortcut\\n\");",
1375         "               #endif",
1376         "               goto store_it;  /* no claim move */",
1377         "       }",
1378         "",
1379         "       this  = pptr(0);        /* 0 = never claim */",
1380         "       trpt->o_pm = 0;",       /* to interpret else in never claim */
1381         "",
1382         "       tt    = (int)   ((P0 *)this)->_p;",
1383         "       ot    = (uchar) ((P0 *)this)->_t;",
1384         "",
1385         "               #ifdef HAS_UNLESS",
1386         "       E_state = 0;",
1387         "               #endif",
1388         "       for (t2 = trans[ot][tt]; t2; t2 = t2?t2->nxt:(Trans *)0)",
1389         "       {",
1390         "               #ifdef HAS_UNLESS",
1391         "               if (E_state > 0 && E_state != t2->e_trans)",
1392         "               {       break;",
1393         "               }",
1394         "               #endif",
1395         "               if (do_transit(t2, 0))",
1396         "               {",
1397         "               #ifdef VERBOSE",
1398         "                       if (!reached[ot][t2->st])",
1399         "                       printf(\"depth: %%d -- claim move from %%d -> %%d\\n\",",
1400         "                               trpt->o_tt, ((P0 *)this)->_p, t2->st);",
1401         "               #endif",
1402         "               #ifdef HAS_UNLESS",
1403         "                       E_state = t2->e_trans;",
1404         "               #endif",
1405         "                       if (t2->st > 0)",
1406         "                       {       ((P0 *)this)->_p = t2->st;",
1407         "                               reached[ot][t2->st] = 1;",
1408         "               #ifndef NOCLAIM",
1409         "                               if (stopstate[ot][t2->st])",
1410         "                               {       uerror(\"end state in claim reached\");",
1411         "                               }",
1412         "               #endif",
1413         "                       }",
1414         "                       if (now._nr_pr == 0)    /* claim terminated */",
1415         "                               uerror(\"end state in claim reached\");",
1416         "",
1417         "               #ifdef PEG",
1418         "                       peg[t2->forw]++;",
1419         "               #endif",
1420         "                       trpt->o_pm |= 1;",
1421         "                       if (t2->atom&2)",
1422         "                       { Uerror(\"atomic in claim not supported in BFS\");",
1423         "                       }",
1424         "store_it:",
1425         "",
1426         "       #endif",        /* VERI */
1427         "",
1428         "       #if defined(BITSTATE)",
1429         "                       if (!b_store((char *)&now, vsize))",
1430         "       #elif defined(MA)",
1431         "                       if (!g_store((char *)&now, vsize, 0))",
1432         "       #else",
1433         "                       if (!h_store((char *)&now, vsize))",
1434         "       #endif",
1435         "                       {       static long sdone = (long) 0; long ndone;",
1436         "                               nstates++;",
1437         "       #ifndef NOREDUCE",
1438         "                               trpt->tau |= 64;", /* bfs: succ definitely outside stack */
1439         "       #endif",
1440         "                               ndone = (ulong) (nstates/(freq));",
1441         "                               if (ndone != sdone && mreached%%10 != 0)",
1442         "                               {       snapshot();",
1443         "                                       sdone = ndone;",
1444         "       #if defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(MA)",
1445         "                                       if (nstates > ((double)(1<<(ssize+1))))",
1446         "                                       {       void resize_hashtable(void);",
1447         "                                               resize_hashtable();",
1448         "                                       }",
1449         "       #endif",
1450         "                               }",
1451         "       #if SYNC",
1452         "                               if (boq != -1)",
1453         "                                       midrv++;",
1454         "                               else if (oboq != -1)",
1455         "                               {       Trail *x;",
1456         "                                       x = (Trail *) trpt->ostate; /* pre-rv state */",
1457         "                                       if (x) x->o_pm |= 4; /* mark success */",
1458         "                               }",
1459         "       #endif",
1460         "                               push_bfs(ntrpt, trpt->o_tt+1);",
1461         "                       } else",
1462         "                       {       truncs++;",
1463
1464         "       #if defined(Q_PROVISO) && !defined(NOREDUCE) && defined(FULLSTACK)",
1465         "               #if !defined(BITSTATE)",
1466         "                               if (Lstate && Lstate->tagged)",
1467         "                               {  trpt->tau |= 64;",
1468         "                               }",
1469         "               #else",
1470         "                               if (trpt->tau&32)",
1471         "                               {  BFS_State *tprov;",
1472         "                                  for (tprov = bfs_trail; tprov; tprov = tprov->nxt)",
1473         "                                       if (tprov->onow->sv != (State *) 0",
1474         "                                       &&  memcmp((uchar *)&now, (uchar *)tprov->onow->sv, vsize) == 0)",
1475         "                                       {       trpt->tau |= 64;",
1476         "                                               break;  /* state is in queue */",
1477         "                               }       }",
1478         "               #endif",
1479         "       #endif",
1480         "                       }",
1481         "       #ifdef VERI",
1482         "                       ((P0 *)this)->_p = tt;  /* reset claim */",
1483         "                       if (t2)",
1484         "                               do_reverse(t2, 0, 0);",
1485         "                       else",
1486         "                               break;",
1487         "       }       }",
1488         "       this = othis;",
1489         "       trpt->o_pm = o_opm;",
1490         "       #endif",
1491         "}",
1492         "",
1493         "void",
1494         "bfs(void)",
1495         "{      Trans *t; Trail *otrpt, *x;",
1496         "       uchar _n, _m, ot, nps = 0;",
1497         "       int tt, E_state;",
1498         "       short II, From = (short) (now._nr_pr-1), To = BASE;",
1499         "       short oboq = boq;",
1500         "",
1501         "       ntrpt = (Trail *) emalloc(sizeof(Trail));",
1502         "       trpt->ostate = (H_el *) 0;",
1503         "       trpt->tau = 0;",
1504         "",
1505         "       trpt->o_tt = -1;",
1506         "       store_state(ntrpt, 0, oboq);    /* initial state */",
1507         "",
1508         "       while ((otrpt = pop_bfs()))     /* also restores now */",
1509         "       {       memcpy((char *) trpt, (char *) otrpt, sizeof(Trail));",
1510         "       #if defined(C_States) && (HAS_TRACK==1)",
1511         "               c_revert((uchar *) &(now.c_state[0]));",
1512         "       #endif",
1513         "               if (trpt->o_pm & 4)",
1514         "               {",
1515         "       #ifdef VERBOSE",
1516         "                       printf(\"Revisit of atomic not needed (%%d)\\n\",",
1517         "                               trpt->o_pm);",  /* at least 1 rv succeeded */
1518         "       #endif",
1519         "                       continue;",
1520         "               }",
1521         "       #ifndef NOREDUCE",
1522         "               nps = 0;",
1523         "       #endif",
1524         "               if (trpt->o_pm == 8)",
1525         "               {       revrv++;",
1526         "                       if (trpt->tau&8)",
1527         "                       {",
1528         "       #ifdef VERBOSE",
1529         "                               printf(\"Break atomic (pm:%%d,tau:%%d)\\n\",",
1530         "                                       trpt->o_pm, trpt->tau);",
1531         "       #endif",
1532         "                               trpt->tau &= ~8;",
1533         "                       }",
1534         "       #ifndef NOREDUCE",
1535         "                       else if (trpt->tau&32)",        /* was a preselected move */
1536         "                       {",
1537         "               #ifdef VERBOSE",
1538         "                               printf(\"Void preselection (pm:%%d,tau:%%d)\\n\",",
1539         "                                       trpt->o_pm, trpt->tau);",
1540         "               #endif",
1541         "                               trpt->tau &= ~32;",
1542         "                               nps = 1; /* no preselection in repeat */",
1543         "                       }",
1544         "       #endif",
1545         "               }",
1546         "               trpt->o_pm &= ~(4|8);",
1547         "               if (trpt->o_tt > mreached)",
1548         "               {       mreached = trpt->o_tt;",
1549         "                       if (mreached%%10 == 0)",
1550         "                       {       snapshot();",
1551         "               }       }",
1552         "               depth = trpt->o_tt;",
1553
1554         "               if (depth >= maxdepth)",
1555         "               {",
1556         "       #if SYNC",
1557         "                       Trail *x;",
1558         "                       if (boq != -1)",
1559         "                       {       x = (Trail *) trpt->ostate;",
1560         "                               if (x) x->o_pm |= 4; /* not failing */",
1561         "                       }",
1562         "       #endif",
1563         "                       truncs++;",
1564         "                       if (!warned)",
1565         "                       {       warned = 1;",
1566         "                               printf(\"error: max search depth too small\\n\");",
1567         "                       }",
1568         "                       if (bounded)",
1569         "                       {       uerror(\"depth limit reached\");",
1570         "                       }",
1571         "                       continue;",
1572         "               }",
1573         "       #ifndef NOREDUCE",
1574         "               if (boq == -1 && !(trpt->tau&8) && nps == 0)",
1575         "               for (II = now._nr_pr-1; II >= BASE; II -= 1)",
1576         "               {",
1577         "Pickup:                this = pptr(II);",
1578         "                       tt = (int) ((P0 *)this)->_p;",
1579         "                       ot = (uchar) ((P0 *)this)->_t;",
1580         "                       if (trans[ot][tt]->atom & 8)",  /* safe */
1581         "                       {       t = trans[ot][tt];",
1582         "                               if (t->qu[0] != 0)",
1583         "                               {       Ccheck++;",
1584         "                                       if (!q_cond(II, t))",
1585         "                                               continue;",
1586         "                                       Cholds++;",
1587         "                               }",
1588         "                               From = To = II;",
1589         "                               trpt->tau |= 32; /* preselect marker */",
1590         "               #ifdef DEBUG",
1591         "                               printf(\"%%3ld: proc %%d PreSelected (tau=%%d)\\n\", ",
1592         "                                       depth, II, trpt->tau);",
1593         "               #endif",
1594         "                               goto MainLoop;",
1595         "               }       }",
1596         "               trpt->tau &= ~32;",     /* not preselected */
1597         "       #endif",        /* if !NOREDUCE */
1598         "Repeat:",
1599         "               if (trpt->tau&8)                /* atomic */",
1600         "               {       From = To = (short ) trpt->pr;",
1601         "                       nlinks++;",
1602         "               } else",
1603         "               {       From = now._nr_pr-1;",
1604         "                       To = BASE;",
1605         "               }",
1606         "MainLoop:",
1607         "               _n = _m = 0;",
1608         "               for (II = From; II >= To; II -= 1)",
1609         "               {",
1610         "                       this = pptr(II);",
1611         "                       tt = (int) ((P0 *)this)->_p;",
1612         "                       ot = (uchar) ((P0 *)this)->_t;",
1613         "       #if SYNC",
1614         "                       /* no rendezvous with same proc */",
1615         "                       if (boq != -1 && trpt->pr == II)",
1616         "                       {       continue;",
1617         "                       }",
1618         "       #endif",
1619         "                       ntrpt->pr = (uchar) II;",
1620         "                       ntrpt->st = tt; ",
1621         "                       trpt->o_pm &= ~1; /* no move yet */",
1622         "       #ifdef EVENT_TRACE",
1623         "                       trpt->o_event = now._event;",
1624         "       #endif",
1625
1626         "       #ifdef HAS_PRIORITY",
1627         "                       if (!highest_priority(((P0 *)this)->_pid, II, t))",
1628         "                       {       continue;",
1629         "                       }",
1630         "       #else",
1631         "               #ifdef HAS_PROVIDED",
1632         "                       if (!provided(II, ot, tt, t))",
1633         "                       {       continue;",
1634         "                       }",
1635         "               #endif",
1636         "       #endif",
1637
1638         "       #ifdef HAS_UNLESS",
1639         "                       E_state = 0;",
1640         "       #endif",
1641         "                       for (t = trans[ot][tt]; t; t = t->nxt)",
1642         "                       {",
1643         "       #ifdef HAS_UNLESS",
1644         "                               if (E_state > 0",
1645         "                               &&  E_state != t->e_trans)",
1646         "                                       break;",
1647         "       #endif",
1648         "                               ntrpt->o_t = t;",
1649         "",
1650         "                               oboq = boq;",
1651         "",
1652         "                               if (!(_m = do_transit(t, II)))",
1653         "                                       continue;",
1654         "",
1655         "                               trpt->o_pm |= 1;        /* we moved */",
1656         "                               (trpt+1)->o_m = _m;     /* for unsend */",
1657         "       #ifdef PEG",
1658         "                               peg[t->forw]++;",
1659         "       #endif",
1660         "       #ifdef CHECK",
1661         "                               printf(\"%%3ld: proc %%d exec %%d, \",",
1662         "                                       depth, II, t->forw);",
1663         "                               printf(\"%%d to %%d, %%s %%s %%s\",",
1664         "                                       tt, t->st, t->tp,",
1665         "                                       (t->atom&2)?\"atomic\":\"\",",
1666         "                                       (boq != -1)?\"rendez-vous\":\"\");",
1667         "               #ifdef HAS_UNLESS",
1668         "                               if (t->e_trans)",
1669         "                                       printf(\" (escapes to state %%d)\", t->st);",
1670         "               #endif",
1671         "                               printf(\" %%saccepting [tau=%%d]\\n\",",
1672         "                                       (trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
1673         "       #endif",
1674         "       #ifdef HAS_UNLESS",
1675         "                               E_state = t->e_trans;",
1676         "               #if SYNC>0",
1677         "                               if (t->e_trans > 0 && (boq != -1 /* || oboq != -1 */))",
1678         "                               { fprintf(efd, \"error:\ta rendezvous stmnt in the escape clause\\n\");",
1679         "                                 fprintf(efd, \"\tof an unless stmnt is not compatible with -DBFS\\n\");",
1680         "                                 pan_exit(1);",
1681         "                               }",
1682         "               #endif",
1683         "       #endif",
1684         "                               if (t->st > 0)",
1685         "                               {       ((P0 *)this)->_p = t->st;",
1686         "                               }",
1687         "",
1688         "       /* ptr to pred: */      ntrpt->ostate = (H_el *) otrpt;",
1689         "                               ntrpt->st = tt;",
1690         "                               if (boq == -1 && (t->atom&2))   /* atomic */",
1691         "                                       ntrpt->tau = 8; /* record for next move */",
1692         "                               else",
1693         "                                       ntrpt->tau = 0;",
1694         "                               store_state(ntrpt, (boq != -1 || (t->atom&2)), oboq);",
1695         "       #ifdef EVENT_TRACE",
1696         "                               now._event = trpt->o_event;",
1697         "       #endif",
1698         "                               /* undo move and continue */",
1699         "                               trpt++; /* this is where ovals and ipt are set */",
1700         "                               do_reverse(t, II, _m);  /* restore now. */",
1701         "                               trpt--;",
1702         "       #ifdef CHECK",
1703         "                               enter_critical(GLOBAL_LOCK);    /* verbose mode */",
1704         "               #if NCORE>1",
1705         "                               printf(\"cpu%%d: \", core_id);",
1706         "               #endif",
1707         "                               printf(\"%%3lu: proc %%d \", depth, II);",
1708         "                               printf(\"reverses %%d, %%d to %%d,\",",
1709         "                                       t->forw, tt, t->st);",
1710         "                               printf(\" %%s [abit=%%d,adepth=%%ld,\",",
1711         "                                       t->tp, now._a_t, A_depth);",
1712         "                               printf(\"tau=%%d,%%d]\\n\",",
1713         "                                       trpt->tau, (trpt-1)->tau);",
1714         "                               leave_critical(GLOBAL_LOCK);",
1715         "       #endif",
1716         "                               reached[ot][t->st] = 1;",
1717         "                               reached[ot][tt]    = 1;",
1718         "",
1719         "                               ((P0 *)this)->_p = tt;",
1720         "                               _n |= _m;",
1721         "               }       }",
1722         "       #ifndef NOREDUCE",      /* with PO */
1723         "               /* preselected - no succ definitely outside stack */",
1724         "               if ((trpt->tau&32) && !(trpt->tau&64))",
1725         "               {       From = now._nr_pr-1; To = BASE;",
1726         "               #ifdef DEBUG",
1727         "                       cpu_printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
1728         "                               depth, II+1, (int) _n, trpt->tau);",
1729         "               #endif",
1730         "                       _n = 0; trpt->tau &= ~32;",
1731         "                       if (II >= BASE)",
1732         "                       {       goto Pickup;",
1733         "                       }",
1734         "                       goto MainLoop;",
1735         "               }",
1736         "               trpt->tau &= ~(32|64);",
1737         "       #endif",        /* PO */
1738         "               if (_n != 0)",
1739         "               {       continue;",
1740         "               }",
1741         "       #ifdef DEBUG",
1742         "               printf(\"%%3ld: no move [II=%%d, tau=%%d, boq=%%d, _nr_pr=%%d]\\n\",",
1743         "                       depth, II, trpt->tau, boq, now._nr_pr);",
1744         "       #endif",
1745         "               if (boq != -1)",
1746         "               {       failedrv++;",
1747         "                       x = (Trail *) trpt->ostate;     /* pre-rv state */",
1748         "                       if (!x)",
1749         "                       {       continue;               /* root state */",
1750         "                       }",
1751         "                       if ((x->tau&8) || (x->tau&32)) /* break atomic or preselect at parent */",
1752         "                       {       x->o_pm |= 8; /* mark failure */",
1753         "                               this = pptr(otrpt->pr);",
1754         "       #ifdef VERBOSE",
1755         "                               printf(\"\\treset state of %%d from %%d to %%d\\n\",",
1756         "                                       otrpt->pr, ((P0 *)this)->_p, otrpt->st);",
1757         "       #endif",
1758         "                               ((P0 *)this)->_p = otrpt->st;",
1759         "                               unsend(boq);    /* retract rv offer */",
1760         "                               boq = -1;",
1761
1762         "                               push_bfs(x, x->o_tt);",
1763         "       #ifdef VERBOSE",
1764         "                               printf(\"failed rv, repush with %%d\\n\", x->o_pm);",
1765         "       #endif",
1766         "                       }",
1767         "       #ifdef VERBOSE",
1768         "                       else",
1769         "                       {       printf(\"failed rv, tau at parent: %%d\\n\", x->tau);",
1770         "                       }",
1771         "       #endif",
1772         "               } else if (now._nr_pr > 0)",
1773         "               {",
1774         "                       if ((trpt->tau&8))              /* atomic */",
1775         "                       {       trpt->tau &= ~(1|8);    /* 1=timeout, 8=atomic */",
1776         "       #ifdef DEBUG",
1777         "                               printf(\"%%3ld: atomic step proc %%d blocks\\n\",",
1778         "                                       depth, II+1);",
1779         "       #endif",
1780         "                               goto Repeat;",
1781         "                       }",
1782         "",
1783         "                       if (!(trpt->tau&1)) /* didn't try timeout yet */",
1784         "                       {       trpt->tau |=  1;",
1785         "       #ifdef DEBUG",
1786         "                               printf(\"%%ld: timeout\\n\", depth);",
1787         "       #endif",
1788         "                               goto MainLoop;",
1789         "                       }",
1790         "       #ifndef VERI",
1791         "                       if (!noends && !a_cycles && !endstate())",
1792         "                       {       uerror(\"invalid end state\");",
1793         "                       }",
1794         "       #endif",
1795         "       }       }",
1796         "}",
1797         "#endif",       /* !BFS_PAR */
1798         "",
1799         "void",
1800         "putter(Trail *trpt, int fd)",
1801         "{      long j;",
1802         "",
1803         "       if (!trpt) return;",
1804         "",
1805         "       if (trpt != (Trail *) trpt->ostate)",
1806         "               putter((Trail *) trpt->ostate, fd);",
1807         "",
1808         "       if (trpt->o_t)",
1809         "       {       sprintf(snap, \"%%d:%%d:%%d\\n\",",
1810         "                       trcnt++, trpt->pr, trpt->o_t->t_id);",
1811         "               j = strlen(snap);",
1812         "               if (write(fd, snap, j) != j)",
1813         "               {       printf(\"pan: error writing %%s\\n\", fnm);",
1814         "                       pan_exit(1);",
1815         "       }       }",
1816         "}",
1817         "",
1818         "void",
1819         "n_ewrite(int fd, char *s, int n)",
1820         "{      if (write(fd, s, strlen(s)) != strlen(s))",
1821         "       {       printf(\"pan: error writing %%s\\n\", fnm);",
1822         "               pan_exit(1);",
1823         "       }",
1824         "}",
1825         "",
1826         "void",
1827         "nuerror(void)",
1828         "{      int fd = make_trail();",
1829         "       int j;",
1830         "",
1831         "       if (fd < 0) return;",
1832         "       #ifdef VERI",
1833         "               sprintf(snap, \"-2:%%d:-2\\n\", (uchar) ((P0 *)pptr(0))->_t);",
1834         "               n_ewrite(fd, snap, strlen(snap));",
1835         "       #endif",
1836         "       #ifdef MERGED",
1837         "               sprintf(snap, \"-4:-4:-4\\n\");",
1838         "               n_ewrite(fd, snap, strlen(snap));",
1839         "       #endif",
1840         "       trcnt = 1;",
1841         "       putter(trpt, fd);",
1842         "       if (ntrpt->o_t)",       /* 4.2.8 -- Alex example, missing last transition */
1843         "       {       sprintf(snap, \"%%d:%%d:%%d\\n\",",
1844         "                       trcnt++, ntrpt->pr, ntrpt->o_t->t_id);",
1845         "               j = strlen(snap);",
1846         "               n_ewrite(fd, snap, j);",
1847         "       }",
1848         "       close(fd);",
1849         "       if (errors >= upto && upto != 0)",
1850         "       {       wrapup();",
1851         "       }",
1852         "}",
1853         "#endif",       /* BFS */
1854         0,
1855 };
1856
1857 static const char *Code2d[] = {
1858         "clock_t start_time;",
1859         "#if NCORE>1",
1860         "clock_t crash_stamp;",
1861         "#endif",
1862         "#if !defined(WIN32) && !defined(WIN64)",
1863         "struct tms start_tm;",
1864         "#endif",
1865         "",
1866         "#if SYNC",
1867         "extern int q_zero(int);",
1868         "extern int not_RV(int);",
1869         "#endif",
1870         "",
1871         "void",
1872         "start_timer(void)",
1873         "{",
1874         "#if defined(WIN32) || defined(WIN64)",
1875         "       start_time = clock();",
1876         "#else",
1877         "       start_time = times(&start_tm);",
1878         "#endif",
1879         "}",
1880         "",
1881         "double delta_time;",
1882         "",
1883         "void",
1884         "report_time(void)",
1885         "{",
1886         "       printf(\"\\npan: elapsed time %%.3g seconds\\n\", delta_time);",
1887         "       if (delta_time > 0.01)",
1888         "       {       printf(\"pan: rate %%9.8g states/second\\n\", nstates/delta_time);",
1889         "               if (verbose)",
1890         "               {       printf(\"pan: avg transition delay %%.5g usec\\n\",",
1891         "                               delta_time/(nstates+truncs));",
1892         "       }       }",
1893         "}",
1894         "",
1895         "void",
1896         "stop_timer(int report)",
1897         "{      clock_t stop_time;",
1898         "#if !defined(WIN32) && !defined(WIN64)",
1899         "       struct tms stop_tm;",
1900         "       stop_time = times(&stop_tm);",
1901         "       delta_time = ((double) (stop_time - start_time)) / ((double) sysconf(_SC_CLK_TCK));",
1902         "#else",
1903         "       stop_time = clock();",
1904         "       delta_time = ((double) (stop_time - start_time)) / ((double) CLOCKS_PER_SEC);",
1905         "#endif",
1906         "       if (readtrail || delta_time < 0.00) return;",
1907         "#if NCORE>1",
1908         "       if (core_id == 0 && nstates > (double) 0)",
1909         "       {       printf(\"\\ncpu%%d: elapsed time %%.3g seconds (%%g states visited)\\n\",",
1910         "                       core_id, delta_time, nstates);",
1911         "               if (delta_time > 0.01)",
1912         "               {       printf(\"cpu%%d: rate %%g states/second\\n\", core_id, nstates/delta_time);",
1913         "               }",
1914         "               { void check_overkill(void);",
1915         "                 check_overkill();",
1916         "       }       }",
1917         "#else",
1918         "       if (report)",
1919         "       {       report_time();",
1920         "       }",
1921         "#endif",
1922         "}",
1923         "",
1924         "#if NCORE>1",
1925         "#ifdef T_ALERT",
1926         "double t_alerts[17];",
1927         "",
1928         "void",
1929         "crash_report(void)",
1930         "{      int i;",
1931         "       printf(\"crash alert intervals:\\n\");",
1932         "       for (i = 0; i < 17; i++)",
1933         "       {       printf(\"%%d\\t%%g\\n\", i, t_alerts[i]);",
1934         "}      }",
1935         "#endif",
1936         "",
1937         "void",
1938         "crash_reset(void)",
1939         "{      /* false alarm */",
1940         "       if (crash_stamp != (clock_t) 0)",
1941         "       {",
1942         "#ifdef T_ALERT",
1943         "               double delta_time;",
1944         "               int i;",
1945                 "#if defined(WIN32) || defined(WIN64)",
1946         "               delta_time = ((double) (clock() - crash_stamp)) / ((double) CLOCKS_PER_SEC);",
1947                 "#else",
1948         "               delta_time = ((double) (times(&start_tm) - crash_stamp)) / ((double) sysconf(_SC_CLK_TCK));",
1949                 "#endif",
1950         "               for (i = 0; i < 16; i++)",
1951         "               {       if (delta_time <= (i*30))",
1952         "                       {       t_alerts[i] = delta_time;",
1953         "                               break;",
1954         "               }       }",
1955         "               if (i == 16) t_alerts[i] = delta_time;",
1956         "#endif",
1957         "               if (verbose)",
1958         "               printf(\"cpu%%d: crash alert off\\n\", core_id);",
1959         "       }",
1960         "       crash_stamp = (clock_t) 0;",
1961         "}",
1962         "",
1963         "int",
1964         "crash_test(double maxtime)",
1965         "{      double delta_time;",
1966         "       if (crash_stamp == (clock_t) 0)",
1967         "       {       /* start timing */",
1968         "#if defined(WIN32) || defined(WIN64)",
1969         "               crash_stamp = clock();",
1970         "#else",
1971         "               crash_stamp = times(&start_tm);",
1972         "#endif",
1973         "               if (verbose)",
1974         "               {       printf(\"cpu%%d: crash detection\\n\", core_id);",
1975         "               }",
1976         "               return 0;",
1977         "       }",
1978         "#if defined(WIN32) || defined(WIN64)",
1979         "       delta_time = ((double) (clock() - crash_stamp)) / ((double) CLOCKS_PER_SEC);",
1980         "#else",
1981         "       delta_time = ((double) (times(&start_tm) - crash_stamp)) / ((double) sysconf(_SC_CLK_TCK));",
1982         "#endif",
1983         "       return (delta_time >= maxtime);",
1984         "}",
1985         "#endif",
1986         "",
1987         "#ifdef BFS_PAR",
1988         "int ncores = 0;",
1989         "#endif",
1990         "",
1991         "void",
1992         "do_the_search(void)",
1993         "{      int i;",
1994         "       depth = mreached = 0;",
1995         "       trpt = &trail[0];",
1996         "#ifdef VERI",
1997         "       trpt->tau |= 4; /* the claim moves first */",
1998         "#endif",
1999         "       for (i = 0; i < (int) now._nr_pr; i++)",
2000         "       {       P0 *ptr = (P0 *) pptr(i);",
2001         "#ifndef NP",
2002         "               if (!(trpt->o_pm&2)",
2003         "               &&  accpstate[ptr->_t][ptr->_p])",
2004         "               {       trpt->o_pm |= 2;",
2005         "                       break;",
2006         "               }",
2007         "#else",
2008         "               if (!(trpt->o_pm&4)",
2009         "               &&  progstate[ptr->_t][ptr->_p])",
2010         "               {       trpt->o_pm |= 4;",
2011         "                       break;",
2012         "               }",
2013         "#endif",
2014         "       }",
2015         "#ifdef EVENT_TRACE",
2016         "#ifndef NP",
2017         "       if (accpstate[EVENT_TRACE][now._event])",
2018         "       {       trpt->o_pm |= 2;",
2019         "       }",
2020         "#else",
2021         "       if (progstate[EVENT_TRACE][now._event])",
2022         "       {       trpt->o_pm |= 4;",
2023         "       }",
2024         "#endif",
2025         "#endif",
2026         "#if !defined(NOCOMP) && !defined(HC)",
2027         "       Mask[0] = Mask[1] = 1;  /* _nr_pr, _nr_qs */",
2028         "       if (!a_cycles)",
2029         "       {       i = &(now._a_t) - (uchar *) &now;",
2030         "               Mask[i] = 1; /* _a_t */",
2031         "       }",
2032         "       #ifndef NOFAIR",
2033         "               if (!fairness)",
2034         "               {       int j = 0;",
2035         "                       i = &(now._cnt[0]) - (uchar *) &now;",
2036         "                       while (j++ < NFAIR)",
2037         "                               Mask[i++] = 1; /* _cnt[] */",
2038         "               }",
2039         "       #endif",
2040         "#endif",
2041         "#ifndef NOFAIR",
2042         "       if (fairness",
2043         "       &&  (a_cycles && (trpt->o_pm&2)))",
2044         "       {       now._a_t = 2;   /* set the A-bit */",
2045         "               now._cnt[0] = now._nr_pr + 1;", /* NEW: +1 */
2046                 "#ifdef VERBOSE",
2047         "       printf(\"%%3ld: fairness Rule 1, cnt=%%d, _a_t=%%d\\n\",",
2048         "               depth, now._cnt[now._a_t&1], now._a_t);",
2049                 "#endif",
2050         "       }",
2051         "#endif",
2052
2053         "       c_stack_start = (char *) &i; /* meant to be read-only */",
2054
2055         "#if defined(HAS_CODE) && defined (C_INIT)",
2056         "       C_INIT; /* initialization of data that must precede fork() */",
2057         "       c_init_done++;",
2058         "#endif",
2059
2060         "#if defined(C_States) && (HAS_TRACK==1)",
2061         "       /* capture initial state of tracked C objects */",
2062         "       c_update((uchar *) &(now.c_state[0]));",
2063         "#endif",
2064
2065         "#ifdef HAS_CODE",
2066         "       if (readtrail) getrail(); /* no return */",
2067         "#endif",
2068         "#ifndef BFS_PAR",
2069         "       start_timer();",
2070         "#endif",
2071         "#ifdef BFS",
2072         "       #ifdef BFS_PAR",
2073         "               bfs_main(ncores,0);",
2074         "       #else",
2075         "               bfs();",
2076         "       #endif",
2077         "#else",
2078         "       #if defined(C_States) && defined(HAS_STACK) && (HAS_TRACK==1)",
2079         "               /* initial state of tracked & unmatched objects */",
2080         "               c_stack((uchar *) &(svtack->c_stack[0]));",
2081         "       #endif",
2082
2083         "       #if defined(P_RAND) || defined(T_RAND)",
2084         "               srand(s_rand+HASH_NR);", /* do_the_search */
2085         "       #endif",
2086
2087         "       #if NCORE>1",
2088         "               mem_get();",
2089         "       #else",
2090         "               new_state();    /* start 1st DFS */",
2091         "       #endif",
2092         "#endif",
2093         "}",
2094
2095         "#ifdef INLINE_REV",
2096         "uchar",
2097         "do_reverse(Trans *t, short II, uchar M)",
2098         "{      uchar _m = M;",
2099         "       int  tt = (int) ((P0 *)this)->_p;",
2100         "#include BACKWARD_MOVES",
2101         "R999:  return _m;",
2102         "}",
2103         "#endif",
2104
2105         "#ifndef INLINE",
2106         "       #ifdef EVENT_TRACE",
2107         "static char _tp = 'n'; static int _qid = 0;",
2108         "       #endif",
2109         "uchar",
2110         "do_transit(Trans *t, short II)",
2111         "{      uchar _m = 0;",
2112         "       int  tt = (int) ((P0 *)this)->_p;",
2113         "       #ifdef M_LOSS",
2114         "       uchar delta_m = 0;",
2115         "       #endif",
2116         "       #ifdef EVENT_TRACE",
2117         "       short oboq = boq;",
2118         "       uchar ot = (uchar)  ((P0 *)this)->_t;",
2119         "       if (II == -EVENT_TRACE) boq = -1;",
2120                 "#define continue       { boq = oboq; return 0; }",
2121         "       #else",
2122                 "#define continue       return 0",
2123                 "#ifdef SEPARATE",
2124         "       uchar ot = (uchar)  ((P0 *)this)->_t;",
2125                 "#endif",
2126         "       #endif",
2127         "#include FORWARD_MOVES",
2128         "P999:",
2129         "       #ifdef EVENT_TRACE",
2130         "       if (II == -EVENT_TRACE) boq = oboq;",
2131         "       #endif",
2132         "       return _m;",
2133         "       #undef continue",
2134         "}",
2135         "#ifdef EVENT_TRACE",
2136         "void",
2137         "require(char tp, int qid)",
2138         "{      Trans *t;",
2139         "       _tp = tp; _qid = qid;",
2140         "",
2141         "       if (now._event != endevent)",
2142         "       for (t = trans[EVENT_TRACE][now._event]; t; t = t->nxt)",
2143         "       {       if (do_transit(t, -EVENT_TRACE))",
2144         "               {       now._event = t->st;",
2145         "                       reached[EVENT_TRACE][t->st] = 1;",
2146         "       #ifdef VERBOSE",
2147         "       printf(\"       event_trace move to -> %%d\\n\", t->st);",
2148         "       #endif",
2149         "       #ifndef BFS",
2150                 "       #ifndef NP",
2151         "                       if (accpstate[EVENT_TRACE][now._event])",
2152         "                               (trpt+1)->o_pm |= 2;",
2153                 "       #else",
2154         "                       if (progstate[EVENT_TRACE][now._event])",
2155         "                               (trpt+1)->o_pm |= 4;",
2156                 "       #endif",
2157         "       #endif",
2158         "       #ifdef NEGATED_TRACE",
2159         "                       if (now._event == endevent)",
2160         "                       {",
2161                 "       #ifndef BFS",
2162         "                               depth++; trpt++;",
2163                 "       #endif",
2164         "                               uerror(\"event_trace error (all events matched)\");",
2165                 "       #ifndef BFS",
2166         "                               trpt--; depth--;",
2167                 "       #endif",
2168         "                               break;",
2169         "                       }",
2170         "       #endif",
2171         "                       for (t = t->nxt; t; t = t->nxt)",
2172         "                       {       if (do_transit(t, -EVENT_TRACE))",
2173         "                                Uerror(\"non-determinism in event-trace\");",
2174         "                       }",
2175         "                       return;",
2176         "               }",
2177         "       #ifdef VERBOSE",
2178         "                else",
2179         "       printf(\"       event_trace miss '%%c' -- %%d, %%d, %%d\\n\",",
2180         "                       tp, qid, now._event, t->forw);",
2181         "       #endif",
2182         "       }",
2183         "       #ifdef NEGATED_TRACE",
2184         "       now._event = endevent; /* only 1st try will count -- fixed 4.2.6 */",
2185         "       #else", 
2186         "               #ifndef BFS",
2187         "       depth++; trpt++;",
2188         "               #endif",
2189         "       uerror(\"event_trace error (no matching event)\");",
2190         "               #ifndef BFS",
2191         "       trpt--; depth--;",
2192         "               #endif",
2193         "       #endif",
2194         "}",
2195         "#endif",
2196         "int",
2197         "enabled(int iam, int pid)",
2198         "{      Trans *t; uchar *othis = this;",
2199         "       int res = 0; int tt; uchar ot;",
2200         "",
2201         "       pid += BASE;",
2202         "       if (pid == iam)",
2203         "               Uerror(\"used: enabled(pid=thisproc)\");",
2204         "       if (pid < 0 || pid >= (int) now._nr_pr)",
2205         "               return 0;",
2206         "       this = pptr(pid);",
2207         "       TstOnly = 1;",
2208         "       tt = (int) ((P0 *)this)->_p;",
2209         "       ot = (uchar) ((P0 *)this)->_t;",
2210         "       for (t = trans[ot][tt]; t; t = t->nxt)",
2211         "               if (do_transit(t, (short) pid))",
2212         "               {       res = 1;",
2213         "                       break;",
2214         "               }",
2215         "       TstOnly = 0;",
2216         "       this = othis;",
2217         "       return res;",
2218         "}",
2219         "#endif",
2220         "",
2221         "#ifdef HAS_PRIORITY",
2222         "int",
2223         "highest_priority(int pid, short nII, Trans *t)",
2224         "{      int i = pid; uchar *othis = this;",
2225         "",
2226         "#ifdef VERI",
2227         "       if (nII == 0)",
2228         "       {       return 1;", /* never claim */
2229         "       }",
2230         "#endif",
2231         "#ifdef HAS_PROVIDED",
2232         "       i = pid+BASE;",  /* uncorrected process number */
2233         "#endif",
2234         "       if (i < 0",
2235         "       ||  i >= (int) now._nr_pr",
2236         "#ifdef HAS_PROVIDED",
2237         "       || !provided(i, (uchar) ((P0 *)this)->_t, (int) ((P0 *)this)->_p, t)",
2238         "#endif",
2239         "       )",
2240         "       {       return 0;",
2241         "       }",
2242         "",
2243         "       for (i = BASE; i < now._nr_pr; i++)",   /* all except never, if present */
2244         "       {       this = pptr(i);",
2245         "               if (i != pid+BASE",
2246         "               &&  ((P0 *)this)->_priority > ((P0 *)pptr(pid+BASE))->_priority",
2247         "#ifdef HAS_PROVIDED",
2248         "               &&  provided(i, (uchar) ((P0 *)this)->_t, (int) ((P0 *)this)->_p, 0)",
2249         "#endif",
2250         "               &&  enabled(i+1, i-BASE))", /* enabled adds back BASE in 2nd arg */
2251         "               {       this = othis;",
2252         "                       return 0;",
2253         "       }       }",
2254         "       this = othis;",
2255         "       return 1;",
2256         "}",
2257         "int",
2258         "get_priority(int pid)",
2259         "{      pid += BASE;    /* 6.2.7 */",
2260         "       if (pid < 0 || pid >= (int) now._nr_pr)",
2261         "               return 0;",
2262         "       return ((P0 *)pptr(pid))->_priority;",
2263         "}",
2264         "int",
2265         "set_priority(int pid, int pr)",
2266         "{      pid += BASE;    /* 6.2.7 */",
2267         "       if (pid < 0 || pid >= (int) now._nr_pr)",
2268         "       {",
2269         "       #ifdef VERBOSE",
2270         "               printf(\"warning: bad pid %%d, no such process (set_priority)\\n\", pid);",
2271         "       #endif",
2272         "               return 1;",
2273         "       }",
2274         "       if (pr < 1 || pr > 255)",
2275         "       {       Uerror(\"priority is out of range\");",
2276         "       }",
2277
2278         "       if (!TstOnly)",
2279         "       {       (trpt+1)->o_priority = ",
2280         "               (((P0 *)pptr(pid))->_priority & 255) | (pid << 8);",
2281         "               ((P0 *)pptr(pid))->_priority = pr;",
2282         "       }",
2283
2284         "       return 1;", /* always executable */
2285         "}",
2286         "#endif",
2287         "",
2288         "void",
2289         "snap_time(void)",
2290         "{      clock_t stop_time;",
2291         "       double delta_time;",
2292         "#if !defined(WIN32) && !defined(WIN64)",
2293         "       struct tms stop_tm;",
2294         "       stop_time  = times(&stop_tm);",
2295         "       delta_time = ((double) (stop_time - start_time)) / ((double) sysconf(_SC_CLK_TCK));",
2296         "#else",
2297         "       stop_time  = clock();",
2298         "       delta_time = ((double) (stop_time - start_time)) / ((double) CLOCKS_PER_SEC);",
2299         "#endif",
2300         "       if (delta_time > 0.01)",
2301         "       {       printf(\"t= %%8.3g \", delta_time);",
2302         "               printf(\"R= %%7.0g\", nstates/delta_time);",
2303         "       }",
2304         "       printf(\"\\n\");",
2305         "       if (quota > 0.1 && delta_time > quota)",
2306         "       {       printf(\"Time limit of %%6.3g minutes exceeded\\n\", quota/60.0);",
2307         "#if NCORE>1",
2308         "               fflush(stdout);",
2309         "               leave_critical(GLOBAL_LOCK);",
2310         "               sudden_stop(\"time-limit\");",
2311         "               exit(1);",
2312         "#endif",
2313         "               wrapup();",
2314         "       }",
2315         "}",
2316         "void",
2317         "snapshot(void)",
2318         "{",
2319         "#ifdef BFS_PAR",
2320         "       e_critical(BFS_GLOB);           /* bfs_par / snapshot */",
2321         "       printf(\"cpu%%d: \", who_am_i);",
2322         "#endif",
2323         "#if NCORE>1",
2324         "       enter_critical(GLOBAL_LOCK);    /* ncore / snapshot */",
2325         "       printf(\"cpu%%d: \", core_id);",
2326         "#endif",
2327         "       printf(\"Depth= %%7ld States= %%8.3g \",",
2328         "#if NCORE>1",
2329         "               (long) (nr_handoffs * z_handoff) +",
2330         "#endif",
2331         "               mreached, nstates);",
2332         "       printf(\"Transitions= %%8.3g \", nstates+truncs);",
2333         "#ifdef MA",
2334         "       printf(\"Nodes= %%7lu \", nr_states);",
2335         "#endif",
2336         "       printf(\"Memory= %%9.3f\\t\", memcnt/1048576.);",
2337         "       snap_time();",
2338         "       fflush(stdout);",
2339         "#if NCORE>1",
2340         "       leave_critical(GLOBAL_LOCK);",
2341         "#endif",
2342         "#ifdef BFS_PAR",
2343         "       x_critical(BFS_GLOB);",
2344         "#endif",
2345         "}",
2346         "#ifdef SC",
2347         "void",
2348         "stack2disk(void)",
2349         "{",
2350         "       if (!stackwrite",
2351         "       &&  (stackwrite = creat(stackfile, TMODE)) < 0)",
2352         "               Uerror(\"cannot create stackfile\");",
2353         "",
2354         "       if (write(stackwrite, trail, DDD*sizeof(Trail))",
2355         "       !=  DDD*sizeof(Trail))",
2356         "               Uerror(\"stackfile write error -- disk is full?\");",
2357         "",
2358         "       memmove(trail, &trail[DDD], (HHH-DDD+2)*sizeof(Trail));",
2359         "       memset(&trail[HHH-DDD+2], 0, (omaxdepth - HHH + DDD - 2)*sizeof(Trail));",
2360         "       CNT1++;",
2361         "}",
2362         "void",
2363         "disk2stack(void)",
2364         "{      long have;",
2365         "",
2366         "       CNT2++;",
2367         "       memmove(&trail[DDD], trail, (HHH-DDD+2)*sizeof(Trail));",
2368         "",
2369         "       if (!stackwrite",
2370         "       ||  lseek(stackwrite, -DDD* (off_t) sizeof(Trail), SEEK_CUR) == -1)",
2371         "               Uerror(\"disk2stack lseek error\");",
2372         "",
2373         "       if (!stackread",
2374         "       &&  (stackread = open(stackfile, 0)) < 0)",
2375         "               Uerror(\"cannot open stackfile\");",
2376         "",
2377         "       if (lseek(stackread, (CNT1-CNT2)*DDD* (off_t) sizeof(Trail), SEEK_SET) == -1)",
2378         "               Uerror(\"disk2stack lseek error\");",
2379         "",
2380         "       have = read(stackread, trail, DDD*sizeof(Trail));",
2381         "       if (have !=  DDD*sizeof(Trail))",
2382         "               Uerror(\"stackfile read error\");",
2383         "}",
2384         "#endif",
2385
2386         "uchar *",
2387         "Pptr(int x)",
2388         "{      if (x < 0 || x >= MAXPROC",     /* does not exist */
2389         "#ifdef TRIX",
2390         "       || !processes[x])",
2391         "#else",
2392         "       || !proc_offset[x])",
2393         "#endif",
2394         "               return noptr;",
2395         "       else",
2396         "               return (uchar *) pptr(x);",
2397         "}\n",
2398         "uchar *",
2399         "Qptr(int x)",
2400         "{      if (x < 0 || x >= MAXQ",
2401         "#ifdef TRIX",
2402         "       || !channels[x])",
2403         "#else",
2404         "       || !q_offset[x])",
2405         "#endif",
2406         "               return noqptr;",
2407         "       else",
2408         "               return (uchar *) qptr(x);",
2409         "}\n",
2410         "",
2411         "#if NCLAIMS>1",
2412         "void",
2413         "select_claim(int n)",
2414         "{      int m, i;",
2415         "       if (n < 0 || n >= NCLAIMS)",
2416         "       {       uerror(\"non-existing claim\");",
2417         "       } else",
2418         "       {       m = ((Pclaim *)pptr(0))->_n;",
2419         "               if (verbose)",
2420         "               {       printf(\"%%d: Claim %%s (%%d), from state %%d\\n\",",
2421         "                               (int) depth, procname[spin_c_typ[n]],",
2422         "                               n, ((Pclaim *)pptr(0))->c_cur[n]);",
2423         "               } else",
2424         "               {       printf(\"pan: ltl formula %%s\\n\",",
2425         "                               procname[spin_c_typ[n]]);",
2426         "               }",
2427         "               ((Pclaim *)pptr(0))->c_cur[m] = ((Pclaim *)pptr(0))->_p;",
2428         "               ((Pclaim *)pptr(0))->_t = spin_c_typ[n];",
2429         "               ((Pclaim *)pptr(0))->_p = ((Pclaim *)pptr(0))->c_cur[n];",
2430         "               ((Pclaim *)pptr(0))->_n = n;",
2431         "               for (i = 0; src_all[i].src != (short *) 0; i++)",
2432         "               {       if (src_all[i].tp == spin_c_typ[n])",
2433         "                       {       src_claim = src_all[i].src;",
2434         "                               break;",
2435         "               }       }", 
2436         "               if (src_all[i].src == (short *) 0)",
2437         "               {       uerror(\"cannot happen: src_ln ref\");",
2438         "       }       }",
2439         "}",
2440         "#else",
2441         "void",
2442         "select_claim(int n)",
2443         "{      if (n != 0) uerror(\"non-existing claim\");",
2444         "}",
2445         "#endif",
2446
2447         "int qs_empty(void);",
2448         "#if !defined(BFS) && (!defined(BITSTATE) || !defined(MA))",
2449         "#ifdef NSUCC",
2450         "int N_succ[512];",
2451         "void",
2452         "tally_succ(int cnt)",
2453         "{      if (cnt < 512) N_succ[cnt]++;",
2454         "       else printf(\"tally_succ: cnt %%d exceeds range\\n\", cnt);",
2455         "}",
2456         "",
2457         "void",
2458         "dump_succ(void)",
2459         "{      int i; double sum = 0.0;",
2460         "       double w_avg = 0.0;",
2461         "       printf(\"Successor counts:\\n\");",
2462         "       for (i = 0; i < 512; i++)",
2463         "       {       sum += (double) N_succ[i];",
2464         "       }",
2465         "       for (i = 0; i < 512; i++)",
2466         "       {       if (N_succ[i] > 0)",
2467         "               {       printf(\"%%3d\t%%10d\t(%%.4g %%%% of total)\\n\",",
2468         "                               i, N_succ[i], (100.0 * (double) N_succ[i])/sum);",
2469         "                       w_avg += (double) i * (double) N_succ[i];",
2470         "       }       }",
2471         "       if (sum > N_succ[0])",
2472         "       printf(\"mean %%.4g (without 0: %%.4g)\\n\", w_avg / sum, w_avg / (sum - (double) N_succ[0]));",
2473         "}",
2474         "#endif",
2475         "",
2476         "#ifdef P_REVERSE",
2477         "       #define FROM_P  (BASE)",
2478         "       #define UPTO_P  (now._nr_pr-1)",
2479         "       #define MORE_P  (II <= To)",            /* p.o. only */
2480         "       #define INI_P   (From-1)",              /* fairness only */
2481         "       #define CNT_P   (1 + (To - From))",     /* P_RAND start */
2482         "       #define NDONE_P (From <= To)",          /* P_RAND continue */
2483         "       #define ALL_P   (II = From; II <= To; II++)",
2484         "#else",
2485         "       #define FROM_P  (now._nr_pr-1)",
2486         "       #define UPTO_P  (BASE)",
2487         "       #define MORE_P  (II >= BASE)",
2488         "       #define INI_P   (From+1)",
2489         "       #define CNT_P   (1 + (From - To))",
2490         "       #define NDONE_P (From >= To)",
2491         "       #define ALL_P   (II = From; II >= To; II--)",
2492         "#endif",
2493         "",
2494         "#ifdef PERMUTED",
2495         "       #define CONTINUE0 { if (reversing&2) { II = oII; } continue; }",
2496         "       #define CONTINUE  { if (reversing&2) { p_reorder(seed); II = oII; } continue; }",
2497         "#else",
2498         "       #define CONTINUE0 { continue; }",
2499         "       #define CONTINUE  { continue; }",
2500         "#endif",
2501
2502         "#ifdef PERMUTED",
2503         "uchar _permutation_[256];",
2504         "void",
2505         "set_reversed(int unused)",
2506         "{      int i, n = now._nr_pr;",
2507         "  #ifdef VERBOSE",
2508         "       printf(\"%%ld: Set_reversed\\n\", depth);",
2509         "  #endif",
2510         "  #if defined(VERI) && !defined(NOCLAIM)",
2511         "       for (i = 1; i < n; i++)",
2512         "       {       _permutation_[i] = n-i;",
2513         "       }",
2514         "  #else",
2515         "       for (i = 0; i < n; i++)",
2516         "       {       _permutation_[i] = n-1-i;",
2517         "       }",
2518         "  #endif",
2519         "}",
2520         "void",
2521         "set_rotated(int unused)",
2522         "{      int i, n = now._nr_pr;",
2523         "  #ifdef VERBOSE",
2524         "       printf(\"%%ld: Set_rotated %%d\\n\", depth, p_rotate);",
2525         "  #endif",
2526         "  #if defined(VERI) && !defined(NOCLAIM)",
2527         "       for (i = 1; i < n; i++)",
2528         "       {       _permutation_[i] = 1+(i-1+p_rotate)%%(n-1);",
2529         "       }",
2530         "  #else",
2531         "       for (i = 0; i < n; i++)",
2532         "       {       _permutation_[i] = (i+p_rotate)%%n;",
2533         "       }",
2534         "  #endif",
2535         "}",
2536         "void",
2537         "set_randrot(int unused)",
2538         "{",
2539         "       if (now._nr_pr > 1)",
2540         "       {       p_rotate = 1+rand()%%(now._nr_pr-1);",
2541         "       } else",
2542         "       {       p_rotate = 0;",
2543         "       }",
2544         "       set_rotated(0);",
2545         "}",
2546         "void",
2547         "set_permuted(int T)",
2548         "{      /* permute nrs 1..n-1, leave 0 in place */",
2549         "       int i, j, k, n = now._nr_pr;",
2550         "       char tmp, *in = &(_permutation_[0]);",
2551         "  #ifdef VERBOSE",
2552         "       printf(\"%%ld: Set_permuted %%d\\n\", depth, T);",
2553         "  #endif",
2554         "       srand(T);",     /* set_permuted */
2555         "       for (i = 0; i < n; i++)",
2556         "       {       in[i] = i;",
2557         "       }",
2558         "       if (n > 1)",
2559         "       {  for (i = 0; i < n; i++)",
2560         "          {",
2561         "  #if defined(VERI) && !defined(NOCLAIM)",
2562         "               j = 1 + rand()%%(n-1);",
2563         "               k = 1 + rand()%%(n-1);",
2564         "  #else",
2565         "               j = rand()%%(n);",
2566         "               k = rand()%%(n);",
2567         "  #endif",
2568         "               tmp   = in[j];",
2569         "               in[j] = in[k];",
2570         "               in[k] = tmp;",
2571         "       }  }",
2572         "}",
2573         "",
2574         "  #ifdef VERBOSE",
2575         "       short",
2576         "       get_permuted(int x)",
2577         "       {       printf(\"%%ld: Get_permuted %%d -> %%d\\n\",",
2578         "                       depth, x, _permutation_[x]);",
2579         "               return (short) _permutation_[x];",
2580         "       }",
2581         "  #else",
2582         "       #define get_permuted(x)  (short) _permutation_[x]",
2583         "  #endif",
2584         "",
2585         "#endif",
2586         "/*",
2587         " * new_state() is the main DFS search routine in the verifier",
2588         " * it has a lot of code ifdef-ed together to support",
2589         " * different search modes, which makes it quite unreadable.",
2590         " * if you are studying the code, use the C preprocessor",
2591         " * to generate a specific version from the pan.c source,",
2592         " * e.g. by saying:",
2593         " *     gcc -E -DNOREDUCE -DBITSTATE pan.c > ppan.c",
2594         " * and then study the resulting file, instead of this version",
2595         " */",
2596         "",
2597         "void",
2598         "new_state(void)",
2599         "{      Trans *t;",
2600         "       uchar _n, _m, ot;",
2601         "#ifdef T_RAND",
2602         "       short ooi, eoi;",
2603         "#endif",
2604         "#ifdef PERMUTED",
2605         "       short oII; uint seed;",
2606         "#endif",
2607         "#ifdef M_LOSS",
2608         "       uchar delta_m = 0;",
2609         "#endif",
2610         "       short II, JJ = 0, kk;",
2611         "       int tt;",
2612         "       short From = FROM_P, To = UPTO_P;",
2613         "#ifdef BCS",
2614         "       trpt->sched_limit = 0; /* at depth=0 only */",
2615         "#endif",
2616         "Down:",
2617         "#ifdef CHECK",
2618         "       cpu_printf(\"%%d: Down - %%s %%saccepting [pids %%d-%%d]\\n\",",
2619         "               depth, (trpt->tau&4)?\"claim\":\"program\",",
2620         "               (trpt->o_pm&2)?\"\":\"non-\", From, To);",
2621         "#endif",
2622
2623         "#ifdef P_RAND",
2624         "       trpt->p_skip = -1;",
2625         "#endif",
2626
2627         "#ifdef SC",
2628         "       if (depth > hiwater)",
2629         "       {       stack2disk();",
2630         "               maxdepth += DDD;",
2631         "               hiwater += DDD;",
2632         "               trpt -= DDD;",
2633         "               if(verbose)",
2634         "               printf(\"zap %%ld: %%ld (maxdepth now %%ld)\\n\",",
2635         "                       CNT1, hiwater, maxdepth);",
2636         "       }",
2637         "#endif",
2638
2639         "       trpt->tau &= ~(16|32|64); /* make sure these are off */",
2640         "#if defined(FULLSTACK) && defined(MA)",
2641         "       trpt->proviso = 0;",
2642         "#endif",
2643         "#ifdef NSUCC",
2644         "       trpt->n_succ = 0;",
2645         "#endif",
2646         "#if NCORE>1",
2647         "       if (mem_hand_off())",
2648         "       {",
2649         "#if SYNC",
2650         "               (trpt+1)->o_n = 1;      /* not a deadlock: as below  */",
2651         "#endif",
2652         "#ifndef LOOPSTATE",
2653         "               (trpt-1)->tau |= 16;    /* worstcase guess: as below */",
2654         "#endif",
2655         "#if NCORE>1 && defined(FULL_TRAIL)",
2656         "               if (upto > 0)",
2657         "               {       Pop_Stack_Tree();",
2658         "               }",
2659         "#endif",
2660         "               goto Up;",
2661         "       }",
2662         "#endif",
2663
2664         "       if (depth >= maxdepth)",
2665         "       {       if (!warned)",
2666         "               { warned = 1;",
2667         "                 printf(\"error: max search depth too small\\n\");",
2668         "               }",
2669         "               if (bounded)",
2670         "               {       uerror(\"depth limit reached\");",
2671         "               }",
2672         "               truncs++;",
2673         "#if SYNC",
2674         "               (trpt+1)->o_n = 1; /* not a deadlock */",
2675         "#endif",
2676         "#ifndef LOOPSTATE",
2677         "               (trpt-1)->tau |= 16;    /* worstcase guess */",
2678         "#endif",
2679
2680         "#if NCORE>1 && defined(FULL_TRAIL)",
2681         "               if (upto > 0)",
2682         "               {       Pop_Stack_Tree();",
2683         "               }",
2684         "#endif",
2685         "               goto Up;",
2686         "       }",
2687         "AllOver:",
2688         "#if (defined(FULLSTACK) && !defined(MA)) || NCORE>1",
2689         "       /* if atomic or rv move, carry forward previous state */",
2690         "       trpt->ostate = (trpt-1)->ostate;",
2691         "#endif",
2692         "#ifdef VERI",
2693         "       if ((trpt->tau&4) || ((trpt-1)->tau&128))",
2694         "#endif",
2695         "       if (boq == -1) {        /* if not mid-rv */",
2696         "#ifndef SAFETY",
2697 #if 0
2698         we want to skip nrpr, nrqs, _a_t and cnt[NFAIR] (in the case of fairness)
2699         this is calculated in S_A, but S_A subtracts 2 bytes,
2700         because nrpr and nrqs are masked in the default state comparisons
2701         so we add those two bytes back here
2702         -- in default comparisons (h_store) we skip _a_t and cnt in the
2703         -- first comparison to find a match on the base-state
2704         -- the _a_t and cnt fields are then separately updated if there was
2705         -- a match on the base state
2706 #endif
2707         "               if ((now._a_t&1) && depth > A_depth)",
2708         "               {       int delta = S_A + 2;",
2709         "                       if (!memcmp((char *)&A_Root + delta, ",
2710         "                               (char *)&now + delta, vsize - delta))",
2711         "                       {",
2712         "#ifndef NOFAIR",
2713         "                          if (fairness && now._cnt[1] != 1) /* was > 1 */",
2714         "                          {",
2715         "       #ifdef CHECK",
2716         "                               printf(\"\tfairness count non-zero\\n\");",
2717         "       #endif",
2718         "                               /* treat as new state */",
2719         "                          } else",
2720         "#endif",
2721         "                          {    depthfound = A_depth;",
2722         "       #ifdef CHECK",
2723         "                               printf(\"matches seed\\n\");",
2724         "       #endif",
2725         "       #ifdef NP",
2726         "                               uerror(\"non-progress cycle\");",
2727         "       #else",
2728         "                               uerror(\"acceptance cycle\");",
2729         "       #endif",
2730         "       #if NCORE>1 && defined(FULL_TRAIL)",
2731         "                               if (upto > 0)",
2732         "                               {       Pop_Stack_Tree();",
2733         "                               }",
2734         "       #endif",
2735         "                               goto Up;",
2736         "                       }  }",
2737         "       #ifdef CHECK",
2738         "                       else",
2739         "                       {",
2740         "                          printf(\"not seed\\n\");",
2741         "                       }",
2742         "       #endif",
2743         "               }",
2744         "#endif",
2745         "               if (!(trpt->tau&8)) /* if no atomic move */",
2746         "               {",
2747         "#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
2748         "                       uchar was_last = now._last;",
2749         "                       now._last = 0;  /* value not stored */",
2750         "#endif",
2751         "#ifdef BITSTATE",
2752                 "#ifdef CNTRSTACK",     /* -> bitstate, reduced, safety */
2753         "               #if defined(BCS) && defined(STORE_CTX)",
2754         "               { int xj;",
2755         "                       for (xj = trpt->sched_limit; xj <= sched_max; xj++)",
2756         "                       {       now._ctx = xj;",
2757         "                               II = b_store((char *)&now, vsize);",
2758         "                               trpt->j6 = j1_spin; trpt->j7 = j2_spin;",
2759         "                               JJ = LL[j1_spin] && LL[j2_spin];",
2760         "                               if (II != 0) { break; }",
2761         "                       }",
2762         "                       now._ctx = 0; /* just in case */",
2763         "               }",
2764         "               #else",
2765         "                       II = b_store((char *)&now, vsize);",
2766         "                       trpt->j6 = j1_spin; trpt->j7 = j2_spin;",
2767         "                       JJ = LL[j1_spin] && LL[j2_spin];",
2768         "               #endif",
2769                 "#else",
2770         "               #ifdef FULLSTACK", /* b_store after onstack_now, to preserve j1-j4 */
2771         "                  #if defined(BCS) && defined(STORE_CTX)",
2772         "                  { int xj;",
2773         "                       now._ctx = 0;",
2774         "                       JJ = onstack_now();",               /* mangles j1 */
2775         "                       for (xj = trpt->sched_limit; xj <= sched_max; xj++)",
2776         "                       {       now._ctx = xj;",
2777         "                               II = b_store((char *)&now, vsize);", /* sets j1-j4 */
2778         "                               if (II != 0) { break; }",
2779         "                       }",
2780         "                       now._ctx = 0;",
2781         "                  }",
2782         "                  #else",
2783         "                       JJ = onstack_now();",               /* mangles j1 */
2784         "                       II = b_store((char *)&now, vsize);", /* sets j1-j4 */
2785         "                  #endif",
2786         "               #else",
2787         "                  #if defined(BCS) && defined(STORE_CTX)",
2788         "                  { int xj;",
2789         "                       for (xj = trpt->sched_limit; xj <= sched_max; xj++)",
2790         "                       {       now._ctx = xj;",
2791         "                               II = b_store((char *)&now, vsize);", /* sets j1-j4 */
2792         "                               JJ = II; /* worstcase guess for p.o. - order corrected in 5.2.1 */",
2793         "                               if (II != 0) { break; }",
2794         "                       }",
2795         "                       now._ctx = 0;",
2796         "                  }",
2797         "                  #else",
2798         "                       II = b_store((char *)&now, vsize);", /* sets j1-j4 */
2799         "                       JJ = II; /* worstcase guess for p.o. - order corrected in 5.2.1 */",
2800         "                  #endif",
2801         "               #endif",
2802                 "#endif",
2803         "#else",
2804                 "#ifdef MA",
2805         "                       II = g_store((char *)&now, vsize, 0);",
2806                         "#ifndef FULLSTACK",
2807         "                       JJ = II;",
2808                         "#else",
2809         "                       JJ = (II == 2)?1:0;",
2810                         "#endif",
2811                 "#else",
2812         "                       II = h_store((char *)&now, vsize);",
2813         "                       /* @hash j1_spin II */",
2814                         "#ifdef FULLSTACK",
2815         "                       JJ = (II == 2)?1:0;",
2816                         "#endif",
2817                 "#endif",
2818         "#endif",
2819         "                       kk = (II == 1 || II == 2);",
2820         /* actually, BCS implies HAS_LAST */
2821         "#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
2822         "                       now._last = was_last;   /* restore value */",
2823         "#endif",
2824
2825                                 /* II==0 new state */
2826                                 /* II==1 old state */
2827                                 /* II==2 on current dfs stack */
2828                                 /* II==3 on 1st dfs stack */
2829         "#ifndef SAFETY",
2830                 /* with multicore we don't know which stack its on */
2831                 /* with HC there's a small chance of a false match - example fifoq 2012 */
2832                 "#if !defined(HC) && (NCORE==1 || defined (SEP_STATE))",
2833         "                       if (II == 2 && ((trpt->o_pm&2) || ((trpt-1)->o_pm&2)))",
2834         "               #ifndef NOFAIR",
2835         "                       if (a_cycles && !fairness) /* 5.1.6 -- example by Hirofumi Watanabe */",
2836         "               #endif",
2837         "                       if (depth > A_depth) /* forum example by adl */",
2838         "                       {",
2839         "                               II = 3; /* Schwoon & Esparza 2005, Gastin&Moro 2004 */",
2840                         "#ifdef VERBOSE",
2841         "                               printf(\"state match on dfs stack\\n\");",
2842                         "#endif",
2843         "                               goto same_case;",
2844         "                       }",
2845                 "#endif",
2846
2847                 "#if defined(FULLSTACK) && defined(BITSTATE)",
2848         "                       if (!JJ && (now._a_t&1) && depth > A_depth)",
2849         "                       {       int oj1 = j1_spin;",
2850         "                               uchar o_a_t = now._a_t;",
2851         "                               now._a_t &= ~(1|16|32);", /* 1st stack  */
2852         "                               if (onstack_now())",      /* changes j1_spin */
2853         "                               {       II = 3;",
2854                 "#ifdef VERBOSE",
2855         "                                       printf(\"state match on 1st dfs stack\\n\");",
2856                 "#endif",
2857         "                               }",
2858         "                               now._a_t = o_a_t;",     /* restore */
2859         "                               j1_spin = oj1;",
2860         "                       }",
2861                 "#endif",
2862         "                       if (II == 3 && a_cycles && (now._a_t&1))",
2863         "                       {",
2864                 "#ifndef NOFAIR",
2865         "                          if (fairness && now._cnt[1] != 1)    /* was > 1 */",
2866         "                          {",
2867                 "       #ifdef CHECK",
2868         "                               printf(\"\tfairness count non-zero\\n\");",
2869                 "       #endif",
2870         "                               II = 0;", /* treat as new state */
2871         "                          } else",
2872                 "#endif",
2873         "                          {",
2874                 "#ifndef BITSTATE",
2875         "                               nShadow--;",
2876                 "#endif",
2877         "same_case:                     if (Lstate) depthfound = Lstate->D;",
2878                 "#ifdef NP",
2879         "                               uerror(\"non-progress cycle\");",
2880                 "#else",
2881         "                               uerror(\"acceptance cycle\");",
2882                 "#endif",
2883         "#if NCORE>1 && defined(FULL_TRAIL)",
2884         "                               if (upto > 0)",
2885         "                               {       Pop_Stack_Tree();",
2886         "                               }",
2887         "#endif",
2888         "                               goto Up;",
2889         "                          }",
2890         "                       }",
2891         "#endif",
2892
2893         "#ifndef NOREDUCE",
2894         "       #ifndef SAFETY",
2895         "               #if NCORE>1 && !defined(SEP_STATE) && defined(V_PROVISO)",
2896         "                       if (II != 0 && (!Lstate || Lstate->cpu_id < core_id))",
2897         "                       {       (trpt-1)->tau |= 16;",  /* treat as a stack state */
2898         "                       }",
2899         "               #endif",
2900         "                       if ((II && JJ) || (II == 3))",
2901         "                       {       /* marker for liveness proviso */",
2902         "               #ifndef LOOPSTATE",
2903         "                               (trpt-1)->tau |= 16;",  /* truncated on stack */
2904         "               #endif",
2905         "                               truncs2++;",
2906         "                       }",
2907                 "#else",
2908         "               #if NCORE>1 && !defined(SEP_STATE) && defined(V_PROVISO)",
2909         "                       if (!(II != 0 && (!Lstate || Lstate->cpu_id < core_id)))",
2910         "                       {       /* treat as stack state */",
2911         "                               (trpt-1)->tau |= 16;",
2912         "                       } else",
2913         "                       {       /* treat as non-stack state */",
2914         "                               (trpt-1)->tau |= 64;",
2915         "                       }",
2916         "               #endif",
2917         "                       if (!II || !JJ)",
2918         "                       {       /* successor outside stack */",
2919         "                               (trpt-1)->tau |= 64;",
2920         "                       }",
2921         "       #endif",
2922         "#endif",
2923         "#if defined(BCS) && (defined(NOREDUCE) || !defined(SAFETY))",
2924         /* needed for BCS - cover cases where it would not otherwise be set */
2925         "                       if (!II || !JJ)",
2926         "                       {       (trpt-1)->tau |= 64;",
2927         "                       }",
2928         "#endif",
2929         "                       if (II)",
2930         "                       {       truncs++;",
2931         "#if NCORE>1 && defined(FULL_TRAIL)",
2932         "                               if (upto > 0)",
2933         "                               {       Pop_Stack_Tree();",
2934         "                                       if (depth == 0)",
2935         "                                       {       return;",
2936         "                               }       }",
2937         "#endif",
2938         "                               goto Up;",
2939         "                       }",
2940         "                       if (!kk)",
2941         "                       {       static long sdone = (long) 0; long ndone;",
2942         "                               nstates++;",
2943         "#if defined(ZAPH) && defined(BITSTATE)",
2944         "                               zstates += (double) hfns;",
2945         "#endif",
2946         "                               ndone = (ulong) (nstates/(freq));",
2947         "                               if (ndone != sdone)",
2948         "                               {       snapshot();",
2949         "                                       sdone = ndone;",
2950         "#if defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(MA)",
2951         "                                       if (nstates > ((double)(ONE_L<<(ssize+1))))",
2952         "                                       {       void resize_hashtable(void);",
2953         "                                               resize_hashtable();",
2954         "                                       }",
2955         "#endif",
2956         "#if defined(ZAPH) && defined(BITSTATE)",
2957         "                                       if (zstates > ((double)(ONE_L<<(ssize-2))))",
2958         "                                       {       /* more than half the bits set */",
2959         "                                               void zap_hashtable(void);",
2960         "                                               zap_hashtable();",
2961         "                                               zstates = 0;",
2962         "                                       }",
2963         "#endif",
2964         "                               }",
2965         "#ifdef SVDUMP",
2966         "                               if (vprefix > 0)",
2967         "       #ifdef SHO",    /* Store Hash Only */
2968         "                       /* always use the same hashfunction, for consistency across runs */",
2969         "                               if (HASH_NR != 0)",
2970         "                               {       int oh = HASH_NR;",
2971         "                                       HASH_NR = 0;",
2972         "                                       d_hash((uchar *) &now, vsize); /* SHO - set K1 */",
2973         "                                       HASH_NR = oh;",
2974         "                               }",
2975         "                               if (write(svfd, (uchar *) &K1, sizeof(ulong)) != sizeof(ulong))",
2976         "       #else",
2977         "                               if (write(svfd, (uchar *) &now, vprefix) != vprefix)",
2978         "       #endif",
2979         "                               {       fprintf(efd, \"writing %%s.svd failed\\n\", PanSource);",
2980         "                                       wrapup();",
2981         "                               }",
2982         "#endif",
2983         "#if defined(MA) && defined(W_XPT)",
2984         "                               if ((ulong) nstates%%W_XPT == 0)",
2985         "                               {       void w_xpoint(void);",
2986         "                                       w_xpoint();",
2987         "                               }",
2988         "#endif",
2989         "                       }",
2990
2991         "#if defined(FULLSTACK) || defined(CNTRSTACK)",
2992         "                       onstack_put();",
2993                 "#ifdef DEBUG2",
2994                 "#if defined(FULLSTACK) && !defined(MA)",
2995         "                       printf(\"%%d: putting %%u (%%d)\\n\", depth,",
2996         "                               trpt->ostate, ",
2997         "                               (trpt->ostate)?trpt->ostate->tagged:0);",
2998                 "#else",
2999         "                       printf(\"%%d: putting\\n\", depth);",
3000                 "#endif",
3001                 "#endif",
3002         "#else",
3003         "       #if NCORE>1",
3004         "                       trpt->ostate = Lstate;",
3005         "       #endif",
3006         "#endif",
3007         "       }       }",
3008
3009         "       if (depth > mreached)",
3010         "               mreached = depth;",
3011         "#ifdef VERI",
3012         "       if (trpt->tau&4)",
3013         "#endif",
3014         "       trpt->tau &= ~(1|2);    /* timeout and -request off */",
3015         "       _n = 0;",
3016         "#if SYNC",
3017         "       (trpt+1)->o_n = 0;",
3018         "#endif",
3019         "#ifdef VERI",
3020         "       if (now._nr_pr == 0)    /* claim terminated */",
3021         "       {       uerror(\"end state in claim reached\");",
3022         "       }",
3023         "       if (stopstate[((Pclaim *)pptr(0))->_t][((Pclaim *)pptr(0))->_p])",
3024         "       {       uerror(\"end state in claim reached\");",
3025         "       }",
3026         "Stutter:",
3027         "       if (trpt->tau&4)        /* must make a claimmove */",
3028         "       {",
3029         "       #ifndef NOFAIR",
3030         "               if ((now._a_t&2)        /* A-bit set */",
3031         "               &&   now._cnt[now._a_t&1] == 1)",
3032         "               {       now._a_t &= ~2;",
3033         "                       now._cnt[now._a_t&1] = 0;",
3034         "                       trpt->o_pm |= 16;",
3035                         "#ifdef DEBUG",
3036         "       printf(\"%%3d: fairness Rule 3.: _a_t = %%d\\n\",",
3037         "               (int) depth, now._a_t);",
3038                         "#endif",
3039         "               }",
3040         "       #endif",
3041         "               II = 0;         /* never */",
3042         "               goto Veri0;",
3043         "       }",
3044         "#endif",
3045         "#ifdef PERMUTED",
3046         "       if (reversing&2)",
3047         "       {       seed = rand();",
3048         "               p_reorder(seed);",
3049         "       }",
3050         "#endif",
3051         "#ifndef NOREDUCE",
3052         "       /* Look for a process with only safe transitions */",
3053         "       /* (special rules apply in the 2nd dfs) */",
3054         "       if (boq == -1 && From != To",
3055         "",
3056         "#ifdef SAFETY",
3057         " #if NCORE>1",
3058         "       && (depth < z_handoff)", /* not for border states */
3059         " #endif",
3060         "       )",
3061         "#else",
3062         " #if NCORE>1",
3063         "       && ((a_cycles) || (!a_cycles && depth < z_handoff))",
3064         " #endif",
3065         " #ifdef BCS",
3066         "       && (sched_max > 0 || depth > BASE)", /* no po in initial state if -L0 */
3067         " #endif",
3068         "       &&  (!(now._a_t&1)",
3069         "           ||  (a_cycles &&",
3070         " #ifndef BITSTATE",
3071                 "#ifdef MA",
3072                         "#ifdef VERI",
3073         "                !((trpt-1)->proviso))",
3074                         "#else",
3075         "               !(trpt->proviso))",
3076                         "#endif",
3077                 "#else",
3078                         "#ifdef VERI",
3079         "                (trpt-1)->ostate &&",
3080         "               !(((char *)&((trpt-1)->ostate->state))[0] & 128))", /* proviso bit in _a_t */
3081                         "#else",
3082         "               !(((char *)&(trpt->ostate->state))[0] & 128))",
3083                         "#endif",
3084                 "#endif",
3085         " #else",
3086                 "#ifdef VERI",
3087         "               (trpt-1)->ostate &&",
3088         "               (trpt-1)->ostate->proviso == 0)",
3089                 "#else",
3090         "               trpt->ostate->proviso == 0)",
3091                 "#endif",
3092         " #endif",
3093         "          ))",
3094         "#endif", /* SAFETY */
3095         "       /* attempt Partial Order Reduction as preselect moves */",
3096         "#ifdef BCS",
3097         "       if (trpt->sched_limit < sched_max)",    /* po only if we can switch */
3098         "#endif",
3099         "       {       for ALL_P {",   /* PO preselect */
3100         "Resume:                /* pick up here if preselect fails */",
3101         "                       this = pptr(II);",
3102         "                       tt = (int) ((P0 *)this)->_p;",
3103         "                       ot = (uchar) ((P0 *)this)->_t;",
3104         "                       if (trans[ot][tt]->atom & 8)",
3105         "                       {       t = trans[ot][tt];",
3106         "                               if (t->qu[0] != 0)",
3107         "                               {       Ccheck++;",
3108         "                                       if (!q_cond(II, t))",
3109         "                                       {       continue;",
3110         "                                       }",
3111         "                                       Cholds++;",
3112         "                               }",
3113         "                               From = To = II; /* preselect process */",
3114         "#ifdef NIBIS",
3115         "                               t->om = 0;",
3116         "#endif",
3117         "                               trpt->tau |= 32; /* preselect marker */",
3118         "#ifdef DEBUG",
3119         "                               printf(\"%%3ld: proc %%d PreSelected (tau=%%d)\\n\", ",
3120         "                                       depth, II, trpt->tau);",
3121         "#endif",
3122         "                               goto Again;",
3123         "                       } else",
3124         "                       {       continue;",
3125         "       }       }       }",
3126         "       trpt->tau &= ~32;",
3127         "#endif",
3128         "#if !defined(NOREDUCE) || (defined(ETIM) && !defined(VERI))",
3129         "Again:",
3130         "#endif",
3131         "       trpt->o_pm &= ~(8|16|32|64); /* clear fairness-marks */",
3132         "#ifndef NOFAIR",
3133         "       if (fairness && boq == -1",
3134                 "#ifdef VERI",
3135         "       && (!(trpt->tau&4) && !((trpt-1)->tau&128))",
3136                 "#endif",
3137         "       && !(trpt->tau&8))",
3138         "       {       /* A_bit = 1; Cnt = N in acc states with A_bit 0 */",
3139         "               if (!(now._a_t&2))",    /* A-bit not set */
3140         "               {       if (a_cycles && (trpt->o_pm&2))",
3141         "                       {       /* Accepting state */",
3142         "                               now._a_t |= 2;",
3143         "                               now._cnt[now._a_t&1] = now._nr_pr + 1;",
3144         "                               trpt->o_pm |= 8;",
3145                 "#ifdef DEBUG",
3146         "       printf(\"%%3ld: fairness Rule 1: cnt=%%d, _a_t=%%d\\n\",",
3147         "                       depth, now._cnt[now._a_t&1], now._a_t);",
3148                 "#endif",
3149         "                       }",
3150         "               } else",                /* A-bit set */
3151         "               {       /* A_bit = 0 when Cnt 0 */",
3152         "                       if (now._cnt[now._a_t&1] == 1)",
3153         "                       {       now._a_t &= ~2;",       /* reset a-bit */
3154         "                               now._cnt[now._a_t&1] = 0;",
3155         "                               trpt->o_pm |= 16;",
3156                 "#ifdef DEBUG",
3157         "       printf(\"%%3ld: fairness Rule 3: _a_t = %%d\\n\",",
3158         "               depth, now._a_t);",
3159                 "#endif",
3160         "       }       }       }",
3161         "#endif",
3162
3163         "#ifdef BCS",   /* bounded context switching */
3164         "       trpt->bcs = trpt->b_pno = 0;    /* initial */",
3165         "       if (From != To          /* not a PO or atomic move */",
3166         "       &&  depth > BASE)       /* there is a prior move */",
3167         "       {       trpt->b_pno = now._last + BASE;",
3168         "               trpt->bcs = B_PHASE1;",
3169         "       #ifdef VERBOSE",
3170         "               printf(\"%%3ld: BCS phase 1 proc %%d limit %%d\\n\",",
3171         "                       depth, trpt->b_pno, trpt->sched_limit);",
3172         "       #endif",
3173         "               /* allow only process b_pno to move in this phase */",
3174         "       }",
3175         "c_switch:      /* jumps here with bcs == B_PHASE2 with or wo B_FORCED added */",
3176         "       #ifdef VERBOSE",
3177         "               printf(\"%%3ld: BCS c_switch phase=%%d pno=%%d [forced %%d]\\n\",",
3178         "                       depth, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
3179         "       #endif",
3180         "#endif",
3181
3182         "#ifdef P_RAND",
3183         "       trpt->p_left = CNT_P;",
3184         "       if (trpt->p_left > 1)",
3185         "       {       trpt->p_skip = rand() %% (trpt->p_left);",
3186         "       } else",
3187         "       {       trpt->p_skip = -1;",
3188         "       }",
3189         "r_switch:",
3190         "       #ifdef VERBOSE",
3191         "               printf(\"%%3ld: P_RAND r_switch p_skip=%%d p_left=%%d\\n\",",
3192         "                       depth, trpt->p_skip, trpt->p_left);",
3193         "       #endif",
3194         "#endif",
3195
3196         "       for ALL_P {",   /* Main Loop */
3197         "#ifdef PERMUTED",
3198         "               if (reversing&2)",
3199         "               {       oII = II;",
3200         "                       if (From != To)", /* not atomic or preselected */
3201         "                       {       II = get_permuted(II);",
3202         "               }       }",
3203         "#endif",
3204         "#ifdef P_RAND",
3205         "               if (trpt->p_skip >= 0)",
3206         "               {       trpt->p_skip--; /* skip random nr of procs */",
3207         "       #ifdef VERBOSE",
3208         "               printf(\"%%3ld: P_RAND skipping %%d [new p_skip=%%d p_left=%%d]\\n\",",
3209         "                       depth, II, trpt->p_skip, trpt->p_left);",
3210         "       #endif",
3211         "                       CONTINUE0;",
3212         "               }",
3213         "               if (trpt->p_left == 0)",
3214         "               {",
3215         "       #ifdef VERBOSE",
3216         "               printf(\"%%3ld: P_RAND done at %%d\\n\", depth, II);",
3217         "       #endif",
3218         "                       break;  /* done */",
3219         "               }",
3220         "       #ifdef VERBOSE",
3221         "               printf(\"%%3ld: P_RAND explore %%d [p_left=%%d]\\n\",",
3222         "                       depth, II, trpt->p_left);",
3223         "       #endif",
3224         "               trpt->p_left--;",
3225         "#endif",
3226
3227         "#if SYNC",
3228         "               /* no rendezvous with same proc */",
3229         "               if (boq != -1 && trpt->pr == II)",
3230         "               {       CONTINUE0;",
3231         "               }",
3232         "#endif",
3233
3234         "#ifdef BCS",   /* never claim with II==0 cannot get here */
3235         "               if ((trpt->bcs & B_PHASE1)",
3236         "               &&  trpt->b_pno != II)",
3237         "               {",
3238         "       #ifdef VERBOSE",
3239         "               printf(\"%%3ld: BCS NotPre II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
3240         "                       depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
3241         "       #endif",
3242         "                       CONTINUE0;",    /* avoid context switch */
3243         "               }",
3244         "       #ifdef VERBOSE",
3245         "               else if ((trpt->bcs & B_PHASE1) && trpt->b_pno == II)",
3246         "               printf(\"%%3ld: BCS IsPre II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
3247         "                       depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
3248         "       #endif",
3249
3250         "               if (trpt->bcs & B_PHASE2)       /* 2nd phase */",
3251         "               {       if (trpt->b_pno == II)  /* was already done in phase 1 */",
3252         "                       {",
3253         "       #ifdef VERBOSE",
3254         "               printf(\"%%3ld: BCS NoRepeat II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
3255         "                       depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
3256         "       #endif",
3257         "                               CONTINUE0;",
3258         "                       }",
3259         "                       if (!(trpt->bcs & B_FORCED)     /* unless forced */",
3260         "                       &&  trpt->sched_limit >= sched_max)",
3261         "                       {",
3262         "       #ifdef VERBOSE",
3263         "               printf(\"%%3ld: BCS Bound II=%%d bcs=%%d pno=%%d [forced %%d]\\n\",",
3264         "                       depth, II, trpt->bcs, trpt->b_pno, (trpt->bcs&B_FORCED)?1:0);",
3265         "       #endif",
3266         "                               CONTINUE0;      /* enforce bound */",
3267         "               }       }",
3268         "#endif",
3269
3270         "#ifdef VERI",
3271         "Veri0:",
3272         "#endif",
3273         "               this = pptr(II);",
3274         "               tt = (int) ((P0 *)this)->_p;",
3275         "               ot = (uchar) ((P0 *)this)->_t;",
3276
3277         "#ifdef NIBIS",
3278         "               /* don't repeat a previous preselected expansion */",
3279         "               /* could hit this if reduction proviso was false */",
3280         "               t = trans[ot][tt];",
3281         "               if (!(trpt->tau&4)",    /* not claim */
3282         "               && !(trpt->tau&1)",     /* not timeout */
3283         "               && !(trpt->tau&32)",    /* not preselected */
3284         "               && (t->atom & 8)",      /* local */
3285         "               && boq == -1",          /* not inside rendezvous */
3286         "               && From != To)",        /* not inside atomic seq */
3287         "               {       if (t->qu[0] == 0",     /* unconditional */
3288         "                       ||  q_cond(II, t))",    /* true condition */
3289         "                       {       _m = t->om;",
3290         "                               if (_m>_n||(_n>3&&_m!=0))",
3291         "                               {       _n=_m;",
3292         "                               }",
3293         "                               CONTINUE0; /* did it before */",
3294         "               }       }",
3295         "#endif",
3296         "               trpt->o_pm &=  ~1; /* no move in this pid yet */",
3297         "#ifdef EVENT_TRACE",
3298         "               (trpt+1)->o_event = now._event;",
3299         "#endif",
3300         "               /* Fairness: Cnt++ when Cnt == II */",
3301         "#ifndef NOFAIR",
3302         "               trpt->o_pm &= ~64; /* didn't apply rule 2 */",
3303         "               if (fairness",
3304         "               && boq == -1",  /* not mid rv - except rcv - NEW 3.0.8 */
3305         "               && !(trpt->o_pm&32)",   /* Rule 2 not in effect */
3306         "               && (now._a_t&2)",       /* A-bit is set */
3307         "               &&  now._cnt[now._a_t&1] == II+2)",
3308         "               {       now._cnt[now._a_t&1] -= 1;",
3309                 "#ifdef VERI",
3310         "                       /* claim need not participate */",
3311         "                       if (II == 1)",
3312         "                               now._cnt[now._a_t&1] = 1;",
3313                 "#endif",
3314                 "#ifdef DEBUG",
3315         "               printf(\"%%3ld: proc %%d fairness \", depth, II);",
3316         "               printf(\"Rule 2: --cnt to %%d (%%d)\\n\",",
3317         "                       now._cnt[now._a_t&1], now._a_t);",
3318                 "#endif",
3319         "                       trpt->o_pm |= (32|64);",
3320         "               }",
3321         "#endif",
3322
3323         "#ifdef HAS_PRIORITY",
3324         "               if (!highest_priority(((P0 *)this)->_pid, II, t))",
3325         "               {       CONTINUE0;",
3326         "               }",
3327         "#else",
3328         "       #ifdef HAS_PROVIDED",
3329         "               if (!provided(II, ot, tt, t))",
3330         "               {       CONTINUE0;",
3331         "               }",
3332         "       #endif",
3333         "#endif",
3334
3335         "               /* check all trans of proc II - escapes first */",
3336         "#ifdef HAS_UNLESS",
3337         "               trpt->e_state = 0;",
3338         "#endif",
3339         "               (trpt+1)->pr = (uchar) II;",    /* for uerror */
3340         "               (trpt+1)->st = tt;",
3341
3342         "#ifdef T_RAND",
3343         "               for (ooi = eoi = 0, t = trans[ot][tt]; t; t = t->nxt, ooi++)",
3344         "               {       if (strcmp(t->tp, \"else\") == 0",
3345         "       #ifdef HAS_UNLESS",
3346         "                       ||  t->e_trans != 0",
3347         "       #endif",
3348         "                       )",
3349         "                       {       eoi++;", /* no break, must count ooi */
3350         "               }       }",
3351         "               if (eoi > 0)",
3352         "               {       t = trans[ot][tt];",
3353         "       #ifdef VERBOSE",
3354         "                       printf(\"randomizer: suppressed, saw else or escape\\n\");",
3355         "       #endif",
3356         "               } else if (ooi > 0)",
3357         "               {       eoi = rand()%%ooi;",
3358         "       #ifdef VERBOSE",
3359         "                       printf(\"randomizer: skip %%d in %%d\\n\", eoi, ooi);",
3360         "       #endif",
3361         "                       for (t = trans[ot][tt]; t; t = t->nxt)",
3362         "                               if (eoi-- <= 0) break;",
3363         "               }",
3364         "domore:",
3365         "               for ( ; t && ooi > 0; t = t->nxt, ooi--)",
3366         "#else", /* ie dont randomize */
3367         "               for (t = trans[ot][tt]; t; t = t->nxt)",
3368         "#endif",
3369         "               {",
3370         "#ifdef HAS_UNLESS",
3371         "                       /* exploring all transitions from",
3372         "                        * a single escape state suffices",
3373         "                        */",
3374         "                       if (trpt->e_state > 0",
3375         "                       &&  trpt->e_state != t->e_trans)",
3376         "                       {",
3377                 "#ifdef DEBUG",
3378         "               printf(\"skip 2nd escape %%d (did %%d before)\\n\",",
3379         "                       t->e_trans, trpt->e_state);",
3380                 "#endif",
3381         "                               break;",
3382         "                       }",
3383         "#endif",
3384         "       #if defined(TRIX) && !defined(TRIX_ORIG) && !defined(BFS)",
3385         "                       (trpt+1)->p_bup = now._ids_[II];",
3386         "       #endif",
3387         "                       (trpt+1)->o_t = t;",    /* for uerror */
3388         "#ifdef INLINE",
3389         "#include FORWARD_MOVES",
3390         "P999:                  /* jumps here when move succeeds */",
3391         "#else",
3392         "                       if (!(_m = do_transit(t, II)))",
3393         "                       {       continue;",
3394         "                       }",
3395         "#endif",
3396         "#ifdef BCS",
3397         "                       if (depth > BASE",      /* has prior move */
3398         "                       && II >= BASE",         /* not claim */
3399         "                       && From != To",         /* not atomic or po */
3400         "       #ifndef BCS_NOFIX",
3401         "                       /* added 5.2.5: prior move was not po */",
3402         "                       && !((trpt-(BASE+1))->tau & 32)",
3403         "       #endif",
3404         "                       && boq == -1",          /* not rv */
3405         "                       && (trpt->bcs & B_PHASE2)",
3406         "                       &&  trpt->b_pno != II   /* context switch */", /* redundant */
3407         "                       && !(trpt->bcs & B_FORCED))     /* unless forced */",
3408         "                       {       (trpt+1)->sched_limit = 1 + trpt->sched_limit;",
3409         "       #ifdef VERBOSE",
3410         "               printf(\"%%3ld: up sched count to %%d\\n\", depth, (trpt+1)->sched_limit);",
3411         "       #endif",
3412         "                       } else",
3413         "                       {       (trpt+1)->sched_limit = trpt->sched_limit;",
3414         "       #ifdef VERBOSE",
3415         "               printf(\"%%3ld: keep sched count at %%d\\n\", depth, (trpt+1)->sched_limit);",
3416         "       #endif",
3417         "                       }",
3418         "#endif",
3419         "                       if (boq == -1)",
3420                 "#ifdef CTL",
3421         "       /* for branching-time, can accept reduction only if */",
3422         "       /* the persistent set contains just 1 transition */",
3423         "                       {       if ((trpt->tau&32) && (trpt->o_pm&1))",
3424         "                                       trpt->tau |= 16;",      /* CTL */
3425         "                               trpt->o_pm |= 1; /* we moved */",
3426         "                       }",
3427                 "#else",
3428         "                               trpt->o_pm |= 1; /* we moved */",
3429                 "#endif",
3430
3431         "#ifdef LOOPSTATE",
3432         "                       if (loopstate[ot][tt])",
3433         "                       {",
3434                 "#ifdef VERBOSE",
3435         "                               printf(\"exiting from loopstate:\\n\");",
3436                 "#endif",
3437         "                               trpt->tau |= 16;",      /* exiting loopstate */
3438         "                               cnt_loops++;",
3439         "                       }",
3440         "#endif",
3441
3442         "#ifdef PEG",
3443         "                       peg[t->forw]++;",
3444         "#endif",
3445         "#if defined(VERBOSE) || defined(CHECK)",
3446                 "#if defined(SVDUMP)",
3447         "       cpu_printf(\"%%3ld: proc %%d exec %%d \\n\", depth, II, t->t_id);",
3448                 "#else",
3449         "       cpu_printf(\"%%3ld: proc %%d exec %%d, %%d to %%d, %%s %%s %%s %%saccepting [tau=%%d]\\n\", ",
3450         "                               depth, II, t->forw, tt, t->st, t->tp,",
3451         "                               (t->atom&2)?\"atomic\":\"\",",
3452         "                               (boq != -1)?\"rendez-vous\":\"\",",
3453         "                               (trpt->o_pm&2)?\"\":\"non-\", trpt->tau);",
3454                 "#ifdef HAS_UNLESS",
3455         "                       if (t->e_trans)",
3456         "                       cpu_printf(\"\\t(escape to state %%d)\\n\", t->st);",
3457                 "#endif",
3458                 "#endif",
3459                 "#ifdef T_RAND",
3460         "                       cpu_printf(\"\\t(randomizer %%d)\\n\", ooi);",
3461                 "#endif",
3462         "#endif",
3463
3464         "#ifdef HAS_LAST",
3465         "#ifdef VERI",
3466         "                       if (II != 0)",
3467         "#endif",
3468         "                               now._last = II - BASE;",
3469         "#endif",
3470         "#ifdef HAS_UNLESS",
3471         "                       trpt->e_state = t->e_trans;",
3472         "#endif",
3473
3474         "                       depth++; trpt++;",
3475         "                       trpt->pr = (uchar) II;",
3476         "                       trpt->st = tt;",
3477         "                       trpt->o_pm &= ~(2|4);",
3478         "                       if (t->st > 0)",
3479         "                       {       ((P0 *)this)->_p = t->st;",
3480         "/*     moved down              reached[ot][t->st] = 1; */",
3481         "                       }",
3482         "#ifndef SAFETY",
3483         "                       if (a_cycles)",
3484         "                       {",
3485                 "#if (ACCEPT_LAB>0 && !defined(NP)) || (PROG_LAB>0 && defined(HAS_NP))",
3486         "                               int ii;",
3487                 "#endif",
3488                 "#define P__Q   ((P0 *)pptr(ii))",
3489                 "#if ACCEPT_LAB>0",
3490                         "#ifdef NP",
3491         "                               /* state 1 of np_ claim is accepting */",
3492         "                               if (((P0 *)pptr(0))->_p == 1)",
3493         "                                       trpt->o_pm |= 2;",
3494                         "#else",
3495         "                               for (ii = 0; ii < (int) now._nr_pr; ii++)",
3496         "                               { if (accpstate[P__Q->_t][P__Q->_p])",
3497         "                                 {     trpt->o_pm |= 2;",
3498         "                                       break;",
3499         "                               } }",
3500                         "#endif",
3501                 "#endif",
3502                 "#if defined(HAS_NP) && PROG_LAB>0",
3503         "                               for (ii = 0; ii < (int) now._nr_pr; ii++)",
3504         "                               { if (progstate[P__Q->_t][P__Q->_p])",
3505         "                                 {     trpt->o_pm |= 4;",
3506         "                                       break;",
3507         "                               } }",
3508                 "#endif",
3509                 "#undef P__Q",
3510         "                       }",
3511         "#endif",
3512         "                       trpt->o_t  =  t; trpt->o_n  = _n;",
3513         "                       trpt->o_ot = ot; trpt->o_tt = tt;",
3514         "                       trpt->o_To = To; trpt->o_m  = _m;",
3515         "                       trpt->tau = 0;",
3516         "#ifdef PERMUTED",
3517         "                       if (reversing&2)",
3518         "                       {       trpt->seed = seed;",
3519         "                               trpt->oII  = oII;",
3520         "                       }",
3521         "#endif",
3522
3523         "#if defined(T_RAND) && !defined(BFS)",
3524         "                       trpt->oo_i = ooi;",
3525         "#endif",
3526         "                       if (boq != -1 || (t->atom&2))",
3527         "                       {       trpt->tau |= 8;",
3528         "#ifdef VERI",
3529         "                               /* atomic sequence in claim */",
3530         "                               if((trpt-1)->tau&4)",
3531         "                                       trpt->tau |= 4;",
3532         "                               else",
3533         "                                       trpt->tau &= ~4;",
3534         "                       } else",
3535         "                       {       if ((trpt-1)->tau&4)",
3536         "                                       trpt->tau &= ~4;",
3537         "                               else",
3538         "                                       trpt->tau |= 4;",
3539         "                       }",
3540         "                       /* if claim allowed timeout, so */",
3541         "                       /* does the next program-step: */",
3542         "                       if (((trpt-1)->tau&1) && !(trpt->tau&4))",
3543         "                               trpt->tau |= 1;",
3544         "#else",
3545         "                       } else",
3546         "                               trpt->tau &= ~8;",
3547         "#endif",
3548         "                       if (boq == -1 && (t->atom&2))",
3549         "                       {       From = To = II; nlinks++;",
3550         "                       } else",
3551         "                       {       From = FROM_P; To = UPTO_P;",
3552         "                       }",
3553         "#if NCORE>1 && defined(FULL_TRAIL)",
3554         "                       if (upto > 0)",
3555         "                       {       Push_Stack_Tree(II, t->t_id);",
3556         "                       }",
3557         "#endif",
3558         "#ifdef TRIX",
3559         "                       if (processes[II])", /* last move could have been a delproc */
3560         "                       {       processes[II]->modified = 1; /* transition in II */",
3561         "       #ifdef V_TRIX",
3562         "                               printf(\"%%4d: process %%d modified\\n\", depth, II);",
3563         "                       } else",
3564         "                       {       printf(\"%%4d: process %%d modified but gone (%%p)\\n\",",
3565         "                                       depth, II, trpt);",
3566         "       #endif",
3567         "                       }",
3568         "#endif",
3569         "                       goto Down;      /* pseudo-recursion */",
3570         "Up:",
3571         "#ifdef TRIX",
3572         "       #ifndef TRIX_ORIG",
3573         "               #ifndef BFS",
3574         "                       now._ids_[trpt->pr] = trpt->p_bup;",
3575         "               #endif",
3576         "       #else",
3577         "                       if (processes[trpt->pr])",
3578         "                       {",
3579         "                               processes[trpt->pr]->modified = 1; /* reverse move */",
3580         "               #ifdef V_TRIX",
3581         "                               printf(\"%%4d: unmodify pr %%d (%%p)\\n\",",
3582         "                                       depth, trpt->pr, trpt);",
3583         "                       } else",
3584         "                       {       printf(\"%%4d: unmodify pr %%d (gone) (%%p)\\n\",",
3585         "                                       depth, trpt->pr, trpt);",
3586         "               #endif",
3587         "                       }",
3588         "       #endif",
3589         "#endif",
3590         "#ifdef CHECK",
3591         "                       cpu_printf(\"%%d: Up - %%s\\n\", depth,",
3592         "                               (trpt->tau&4)?\"claim\":\"program\");",
3593         "#endif",
3594         "#if NCORE>1",
3595         "                       iam_alive();",
3596         "       #ifdef USE_DISK",
3597         "                       mem_drain();",
3598         "       #endif",
3599         "#endif",
3600         "#if defined(MA) || NCORE>1",
3601         "                       if (depth <= 0) return;",
3602         "                       /* e.g., if first state is old, after a restart */",
3603         "#endif",
3604
3605         "#ifdef SC",
3606         "                       if (CNT1 > CNT2",
3607         "                       && depth < hiwater - (HHH-DDD) - 2)",   /* 5.1.6: was + 2 */
3608         "                       {",
3609         "                               trpt += DDD;",
3610         "                               disk2stack();",
3611         "                               maxdepth -= DDD;",
3612         "                               hiwater -= DDD;",
3613         "                               if(verbose)",
3614         "                               printf(\"unzap %%ld: %%ld\\n\", CNT2, hiwater);",
3615         "                       }",
3616         "#endif",
3617
3618         "#ifndef SAFETY",       /* moved earlier in version 5.2.5 */
3619         "                       if ((now._a_t&1) && depth <= A_depth)",
3620         "                               return; /* to checkcycles() */",
3621         "#endif",
3622
3623         "#ifndef NOFAIR",
3624         "                       if (trpt->o_pm&128)     /* fairness alg */",
3625         "                       {       now._cnt[now._a_t&1] = trpt->bup.oval;",
3626         "                               _n = 1; trpt->o_pm &= ~128;",
3627         "                               depth--; trpt--;",
3628                 "#if defined(VERBOSE) || defined(CHECK)",
3629         "       printf(\"%%3ld: reversed fairness default move\\n\", depth);",
3630                 "#endif",
3631         "                               goto Q999;",
3632         "                       }",
3633         "#endif",
3634
3635         "#ifdef HAS_LAST",
3636         "#ifdef VERI",
3637         "                       { long d; Trail *trl;",
3638         "                         now._last = 0;",
3639         "                         for (d = 1; d < depth; d++)",
3640         "                         {     trl = getframe(depth-d); /* was (trpt-d) */",
3641         "                               if (trl->pr != 0)",
3642         "                               { now._last = trl->pr - BASE;",
3643         "                                 break;",
3644         "                       } }     }",
3645         "#else",
3646         "                       now._last = (depth<1)?0:(trpt-1)->pr;",
3647         "#endif",
3648         "#endif",
3649         "#ifdef EVENT_TRACE",
3650         "                       now._event = trpt->o_event;",
3651         "#endif",
3652         "                       t  = trpt->o_t;  _n = trpt->o_n;",
3653         "                       ot = trpt->o_ot; II = trpt->pr;",
3654         "                       tt = trpt->o_tt; this = Pptr(II);",
3655         "                       To = trpt->o_To; _m  = trpt->o_m;",
3656         "#ifdef PERMUTED",
3657         "                       if (reversing&2)",
3658         "                       {       seed = trpt->seed;",
3659         "                               oII  = trpt->oII;",
3660         "                       }",
3661         "#endif",
3662         "#if defined(T_RAND) && !defined(BFS)",
3663         "                       ooi = trpt->oo_i;",
3664         "#endif",
3665         "#ifdef INLINE_REV",
3666         "                       _m = do_reverse(t, II, _m);",
3667         "#else",
3668         "#include BACKWARD_MOVES",
3669         "R999:                  /* jumps here when done */",
3670         "#endif",
3671
3672         "#ifdef VERBOSE",
3673         "                       cpu_printf(\"%%3ld: proc %%d reverses %%d, %%d to %%d\\n\",",
3674         "                               depth, II, t->forw, tt, t->st);",
3675         "                       cpu_printf(\"\\t%%s [abit=%%d,adepth=%%ld,tau=%%d,%%d]\\n\", ",
3676         "                               t->tp, now._a_t, A_depth, trpt->tau, (trpt-1)->tau);",
3677         "#endif",
3678         "#ifndef NOREDUCE",
3679         "                       /* pass the proviso tags */",
3680         "                       if ((trpt->tau&8)       /* rv or atomic */",
3681         "                       &&  (trpt->tau&16))",
3682         "                               (trpt-1)->tau |= 16;",  /* pass upward */
3683         "       #ifdef SAFETY",
3684         "                       if ((trpt->tau&8)       /* rv or atomic */",
3685         "                       &&  (trpt->tau&64))",
3686         "                               (trpt-1)->tau |= 64;",
3687         "       #endif",
3688         "#endif",
3689
3690         "#if defined(BCS) && (defined(NOREDUCE) || !defined(SAFETY))",
3691         /* for BCS, cover cases where 64 is otherwise not handled */
3692         "                       if ((trpt->tau&8)",
3693         "                       &&  (trpt->tau&64))",
3694         "                               (trpt-1)->tau |= 64;",
3695         "#endif",
3696
3697         "                       depth--; trpt--;",
3698         "",
3699         "#ifdef NSUCC",
3700         "                       trpt->n_succ++;",
3701         "#endif",
3702         "#ifdef NIBIS",
3703         "                       (trans[ot][tt])->om = _m; /* head of list */",
3704         "#endif",
3705
3706         "                       /* i.e., not set if rv fails */",
3707         "                       if (_m)",
3708         "                       {       reached[ot][t->st] = 1;",
3709         "                               reached[ot][tt] = 1;",
3710         "                       }",
3711         "#ifdef HAS_UNLESS",
3712         "                       else trpt->e_state = 0; /* undo */",
3713         "#endif",
3714
3715         "                       if (_m>_n||(_n>3&&_m!=0)) _n=_m;",
3716         "                       ((P0 *)this)->_p = tt;",
3717         "               } /* all options */",
3718
3719         "#ifdef T_RAND",
3720         "               if (!t && ooi > 0)",    /* means we skipped some initial options */
3721         "               {       t = trans[ot][tt];",
3722         "       #ifdef VERBOSE",
3723         "                       printf(\"randomizer: continue for %%d more\\n\", ooi);",
3724         "       #endif",
3725         "                       goto domore;",
3726         "               }",
3727         "       #ifdef VERBOSE",
3728         "                 else",
3729         "                       printf(\"randomizer: done\\n\");",
3730         "       #endif",
3731         "#endif",
3732
3733         "#ifndef NOFAIR",
3734         "               /* Fairness: undo Rule 2 */",
3735         "               if ((trpt->o_pm&32)",/* rule 2 was applied */
3736         "               &&  (trpt->o_pm&64))",/* by this process II */
3737         "               {       if (trpt->o_pm&1)",/* it didn't block */
3738         "                       {",
3739                 "#ifdef VERI",
3740         "                               if (now._cnt[now._a_t&1] == 1)",
3741         "                                       now._cnt[now._a_t&1] = 2;",
3742                 "#endif",
3743         "                               now._cnt[now._a_t&1] += 1;",
3744                 "#ifdef VERBOSE",
3745         "               printf(\"%%3ld: proc %%d fairness \", depth, II);",
3746         "               printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
3747         "                       now._cnt[now._a_t&1], now._a_t);",
3748                 "#endif",
3749         "                               trpt->o_pm &= ~(32|64);",
3750         "                       } else",        /* process blocked  */
3751         "                       {       if (_n > 0)", /* a prev proc didn't */
3752         "                               {",     /* start over */
3753         "                                       trpt->o_pm &= ~64;",
3754         "                                       II = INI_P;", /* after loop incr II == From */
3755         "               }       }       }",
3756         "#endif",
3757         "#ifdef VERI",
3758         "               if (II == 0)",
3759         "               {       break;  /* never claim */",
3760         "               }",
3761         "#endif",
3762         "               CONTINUE;",
3763         "       } /* ALL_P */",
3764
3765         "#ifdef NSUCC",
3766         "       tally_succ(trpt->n_succ);",
3767         "#endif",
3768
3769         "#ifdef P_RAND",
3770         "       if (trpt->p_left > 0 && NDONE_P)",
3771         "       {       trpt->p_skip = -1; /* probably rendundant */",
3772         "       #ifdef VERBOSE",
3773         "               printf(\"%%3ld: P_RAND -- explore remainder\\n\", depth);",
3774         "       #endif",
3775         "               goto r_switch; /* explore the remaining procs */",
3776         "       } else",
3777         "       {",
3778         "       #ifdef VERBOSE",
3779         "               printf(\"%%3ld: P_RAND -- none left\\n\", depth);",
3780         "       #endif",
3781         "       }",
3782         "#endif",
3783
3784         "#ifdef BCS",
3785         "       if (trpt->bcs & B_PHASE1)",
3786         "       {       trpt->bcs = B_PHASE2;   /* start 2nd phase */",
3787         "               if (_n == 0 || !(trpt->tau&64)) /* pre-move unexecutable or led to stackstate */",
3788         "               {       trpt->bcs |= B_FORCED; /* forced switch */",
3789         "               }",
3790         "       #ifdef VERBOSE",
3791         "               printf(\"%%3ld: BCS move to phase 2, _n=%%d %%s\\n\", depth, _n,",
3792         "                       (trpt->bcs & B_FORCED)?\"forced\":\"free\");",
3793         "       #endif",
3794         "               From = FROM_P; To = UPTO_P;",
3795         "               goto c_switch;",
3796         "       }",
3797         "",
3798         "       if (_n == 0     /* no process could move */",
3799         "       &&  II >= BASE  /* not the never claim */",
3800         "       &&  trpt->sched_limit >= sched_max)",
3801         "       {       _n = 1;",
3802         "       #ifdef VERBOSE",
3803         "               printf(\"%%3ld: BCS not a deadlock\\n\", depth);",
3804         "       #endif",
3805         "       }",
3806         "#endif",
3807
3808         "#ifndef NOFAIR",
3809         "       /* Fairness: undo Rule 2 */",
3810         "       if (trpt->o_pm&32)      /* remains if proc blocked */",
3811         "       {",
3812                 "#ifdef VERI",
3813         "               if (now._cnt[now._a_t&1] == 1)",
3814         "                       now._cnt[now._a_t&1] = 2;",
3815                 "#endif",
3816         "               now._cnt[now._a_t&1] += 1;",
3817                 "#ifdef VERBOSE",
3818         "               printf(\"%%3ld: proc -- fairness \", depth);",
3819         "               printf(\"undo Rule 2, cnt=%%d, _a_t=%%d\\n\",",
3820         "                       now._cnt[now._a_t&1], now._a_t);",
3821                 "#endif",
3822         "               trpt->o_pm &= ~32;",
3823         "       }",
3824         "#ifndef NP",
3825         /* 12/97 non-progress cycles cannot be created
3826          * by stuttering extension, here or elsewhere
3827          */
3828         "       if (fairness",
3829         "       &&  _n == 0             /* nobody moved */",
3830                 "#ifdef VERI",
3831                 "       && !(trpt->tau&4)       /* in program move */",
3832                 "#endif",
3833         "       && !(trpt->tau&8)       /* not an atomic one */",
3834                 "#ifdef ETIM",
3835                 "       &&  (trpt->tau&1)       /* already tried timeout */",
3836                 "#endif",
3837                 "#ifndef NOREDUCE",
3838                 "       /* see below  */",
3839                 "       && !((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
3840                 "#endif",
3841         "       && now._cnt[now._a_t&1] > 0)    /* needed more procs */",
3842         "       {       depth++; trpt++;",
3843         "               trpt->o_pm |= 128 | ((trpt-1)->o_pm&(2|4));",
3844         "               trpt->bup.oval = now._cnt[now._a_t&1];",
3845         "               now._cnt[now._a_t&1] = 1;",
3846                 "#ifdef VERI",
3847         "               trpt->tau = 4;",
3848                 "#else",
3849         "               trpt->tau = 0;",
3850                 "#endif",
3851         "               From = FROM_P; To = UPTO_P;",
3852                 "#if defined(VERBOSE) || defined(CHECK)",
3853         "               printf(\"%%3ld: fairness default move \", depth);",
3854         "               printf(\"(all procs block)\\n\");",
3855                 "#endif",
3856         "               goto Down;",
3857         "       }",
3858         "#endif",
3859         "Q999:  /* returns here with _n>0 when done */;",
3860
3861         "       if (trpt->o_pm&8)",
3862         "       {       now._a_t &= ~2;",
3863         "               now._cnt[now._a_t&1] = 0;",
3864         "               trpt->o_pm &= ~8;",
3865                 "#ifdef VERBOSE",
3866         "               printf(\"%%3ld: fairness undo Rule 1, _a_t=%%d\\n\",",
3867         "                       depth, now._a_t);",
3868                 "#endif",
3869         "       }",
3870         "       if (trpt->o_pm&16)",
3871         "       {       now._a_t |= 2;",                /* restore a-bit */
3872         "               now._cnt[now._a_t&1] = 1;",     /* NEW: restore cnt */
3873         "               trpt->o_pm &= ~16;",
3874                 "#ifdef VERBOSE",
3875         "               printf(\"%%3ld: fairness undo Rule 3, _a_t=%%d\\n\",",
3876         "                       depth, now._a_t);",
3877                 "#endif",
3878         "       }",
3879         "#endif",
3880
3881         "#ifndef NOREDUCE",
3882 "#ifdef SAFETY",
3883         "       #ifdef LOOPSTATE",
3884         "         /* at least one move that was preselected at this */",
3885         "         /* level, blocked or was a loop control flow point */",
3886         "         if ((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
3887         "       #else",
3888         "         /* preselected move - no successors outside stack */",
3889         "         if ((trpt->tau&32) && !(trpt->tau&64))",
3890         "       #endif",
3891         "         {     From = FROM_P; To = UPTO_P; /* undo From == To */",
3892         "       #ifdef DEBUG",
3893         "               printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
3894         "                       depth, II+1, _n, trpt->tau);",
3895         "       #endif",
3896         "               _n = 0; trpt->tau &= ~(16|32|64);",
3897
3898         "               if (MORE_P)     /* II already restored and updated */",
3899         "               {       goto Resume;",
3900         "               } else",
3901         "               {       goto Again;",
3902         "         }     }",
3903 "#else",
3904         "       /* at least one move that was preselected at this */",
3905         "       /* level, blocked or truncated at the next level  */",
3906         "       if ((trpt->tau&32) && (_n == 0 || (trpt->tau&16)))",
3907         "       {",
3908         "       #ifdef DEBUG",
3909         "               printf(\"%%3ld: proc %%d UnSelected (_n=%%d, tau=%%d)\\n\", ",
3910         "               depth, II+1, (int) _n, trpt->tau);",
3911         "       #endif",
3912         "               if (a_cycles && (trpt->tau&16))",
3913         "               {       if (!(now._a_t&1))",
3914         "                       {",
3915         "       #ifdef DEBUG",
3916         "                       printf(\"%%3ld: setting proviso bit\\n\", depth);",
3917         "       #endif",
3918         "#ifndef BITSTATE",
3919                 "#ifdef MA",
3920                         "#ifdef VERI",
3921         "                       (trpt-1)->proviso = 1;",
3922                         "#else",
3923         "                       trpt->proviso = 1;",
3924                         "#endif",
3925                 "#else",
3926                         "#ifdef VERI",
3927         "                       if ((trpt-1)->ostate)",
3928         "                       ((char *)&((trpt-1)->ostate->state))[0] |= 128;",
3929                         "#else",
3930         "                       ((char *)&(trpt->ostate->state))[0] |= 128;",
3931                         "#endif",
3932                 "#endif",
3933         "#else",
3934                 "#ifdef VERI",
3935         "                       if ((trpt-1)->ostate)",
3936         "                       (trpt-1)->ostate->proviso = 1;",
3937                 "#else",
3938         "                       trpt->ostate->proviso = 1;",
3939                 "#endif",
3940         "#endif",
3941         "                               From = FROM_P; To = UPTO_P;",
3942         "                               _n = 0; trpt->tau &= ~(16|32|64);",
3943         "                               goto Again; /* do full search */",
3944         "                       } /* else accept reduction */",
3945         "               } else",
3946         "               {       From = FROM_P; To = UPTO_P;",
3947         "                       _n = 0; trpt->tau &= ~(16|32|64);",
3948         "                       if (MORE_P)     /* II already updated */",
3949         "                       {       goto Resume;",
3950         "                       } else",
3951         "                       {       goto Again;",
3952         "       }       }       }",
3953 "#endif",
3954         "#endif",
3955
3956         "       if (_n == 0 || ((trpt->tau&4) && (trpt->tau&2)))",
3957         "       {",
3958                 "#ifdef DEBUG",
3959         "               cpu_printf(\"%%3ld: no move [II=%%d, tau=%%d, boq=%%d]\\n\",",
3960         "                       depth, II, trpt->tau, boq);",
3961                 "#endif",
3962         "#if SYNC",
3963         "               /* ok if a rendez-vous fails: */",
3964         "               if (boq != -1) goto Done;",
3965         "#endif",
3966         "               /* ok if no procs or we're at maxdepth */",
3967         "               if ((now._nr_pr == 0 && (!strict || qs_empty()))",
3968         "               ||  depth >= maxdepth-1) goto Done;     /* undo change from 5.2.3 */",
3969
3970         "               if ((trpt->tau&8) && !(trpt->tau&4))",
3971         "               {       trpt->tau &= ~(1|8);",
3972         "                       /* 1=timeout, 8=atomic */",
3973         "                       From = FROM_P; To = UPTO_P;",
3974                 "#ifdef DEBUG",
3975         "               cpu_printf(\"%%3ld: atomic step proc %%d unexecutable\\n\", depth, II+1);",
3976                 "#endif",
3977         "#ifdef VERI",
3978         "                       trpt->tau |= 4; /* switch to claim */",
3979         "#endif",
3980         "                       goto AllOver;",
3981         "               }",
3982
3983         "#ifdef ETIM",
3984         "               if (!(trpt->tau&1)) /* didn't try timeout yet */",
3985         "               {",
3986         "#ifdef VERI",
3987         "                       if (trpt->tau&4)",
3988         "                       {",
3989                 "#ifndef NTIM",
3990         "                               if (trpt->tau&2) /* requested */",
3991                 "#endif",
3992         "                               {       trpt->tau |=  1;",
3993         "                                       trpt->tau &= ~2;",
3994         "       #ifdef DEBUG",
3995         "                               cpu_printf(\"%%d: timeout\\n\", depth);",
3996         "       #endif",
3997         "                                       goto Stutter;",
3998         "                       }       }",
3999         "                       else",
4000         "                       {       /* only claim can enable timeout */",
4001         "                               if ((trpt->tau&8)",
4002         "                               &&  !((trpt-1)->tau&4))",
4003         "/* blocks inside an atomic */          goto BreakOut;",
4004         "       #ifdef DEBUG",
4005         "                               cpu_printf(\"%%d: req timeout\\n\",",
4006         "                                       depth);",
4007         "       #endif",
4008         "                               (trpt-1)->tau |= 2; /* request */",
4009         "       #if NCORE>1 && defined(FULL_TRAIL)",
4010         "                               if (upto > 0)",
4011         "                               {       Pop_Stack_Tree();",
4012         "                               }",
4013         "       #endif",
4014         "                               goto Up;",
4015         "                       }",
4016         "#else",
4017         "       #ifdef DEBUG",
4018         "                       cpu_printf(\"%%d: timeout\\n\", depth);",
4019         "       #endif",
4020         "                       trpt->tau |=  1;",
4021         "                       goto Again;",
4022         "#endif",
4023         "               }",
4024         "#endif",
4025
4026         /* old location of atomic block code */
4027         "#ifdef VERI",
4028         "BreakOut:",
4029                 "#ifndef NOSTUTTER",
4030         "               if (!(trpt->tau&4))",
4031         "               {       trpt->tau |= 4;   /* claim stuttering */",
4032         "                       trpt->tau |= 128; /* stutter mark */",
4033                                 "#ifdef DEBUG",
4034         "                       cpu_printf(\"%%d: claim stutter\\n\", depth);",
4035                                 "#endif",
4036         "                       goto Stutter;",
4037         "               }",
4038                 "#else",
4039         "               ;",
4040                 "#endif",
4041         "#else",
4042         "               if (!noends && !a_cycles && !endstate())",
4043         "               {       depth--; trpt--;        /* new 4.2.3 */",
4044         "                       uerror(\"invalid end state\");",
4045         "                       depth++; trpt++;",
4046         "               }",
4047                 "#ifndef NOSTUTTER",
4048         "               else if (a_cycles && (trpt->o_pm&2)) /* new 4.2.4 */",
4049         "               {       depth--; trpt--;",
4050         "                       uerror(\"accept stutter\");",
4051         "                       depth++; trpt++;",
4052         "               }",
4053                 "#endif",
4054         "#endif",
4055         "       }",
4056         "Done:",
4057         "       if (!(trpt->tau&8))     /* not in atomic seqs */",
4058         "       {",
4059
4060 "#ifndef MA",
4061         "#if defined(FULLSTACK) || defined(CNTRSTACK)",
4062         "#ifdef VERI",
4063         "               if (boq == -1",
4064         "               &&  (((trpt->tau&4) && !(trpt->tau&128))",
4065         "               ||  ( (trpt-1)->tau&128)))",
4066         "#else",
4067         "               if (boq == -1)",
4068         "#endif",
4069         "               {",
4070                 "#ifdef DEBUG2",
4071                 "#if defined(FULLSTACK)",
4072         "                       printf(\"%%ld: zapping %%u (%%d)\\n\",",
4073         "                               depth, trpt->ostate,",
4074         "                       (trpt->ostate)?trpt->ostate->tagged:0);",
4075                 "#endif",
4076                 "#endif",
4077         "                       onstack_zap();",
4078         "               }",
4079         "#endif",
4080 "#else",
4081         "#ifdef VERI",
4082         "               if (boq == -1",
4083         "               &&  (((trpt->tau&4) && !(trpt->tau&128))",
4084         "               ||  ( (trpt-1)->tau&128)))",
4085         "#else",
4086         "               if (boq == -1)",
4087         "#endif",
4088         "               {",
4089                 "#ifdef DEBUG",
4090         "                       printf(\"%%ld: zapping\\n\", depth);",
4091                 "#endif",
4092         "                       onstack_zap();",
4093                 "#ifndef NOREDUCE",
4094         "                       if (trpt->proviso)",
4095         "                       g_store((char *) &now, vsize, 1);",
4096                 "#endif",
4097         "               }",
4098 "#endif",
4099
4100         "#ifndef SAFETY",
4101         "               if (_n != 0",           /* we made a move */
4102                 "#ifdef VERI",
4103         "               /* --after-- a program-step, i.e., */",
4104         "               /* after backtracking a claim-step */",
4105         "               && (trpt->tau&4)",
4106         "               /* with at least one running process */",
4107         "               /* unless in a stuttered accept state */",
4108         "               && ((now._nr_pr > 1) || (trpt->o_pm&2))",
4109                 "#endif",
4110         "               && !(now._a_t&1))",     /* not in 2nd DFS */
4111         "               {",
4112                 "#ifndef NOFAIR",
4113         "                       if (fairness)", /* implies a_cycles */
4114         "                       {",
4115                         "#ifdef VERBOSE",
4116         "                       cpu_printf(\"Consider check %%d %%d...\\n\",",
4117         "                               now._a_t, now._cnt[0]);",
4118                         "#endif",
4119 #if 0
4120                 the a-bit is set, which means that the fairness
4121                 counter is running -- it was started in an accepting state.
4122                 we check that the counter reached 1, which means that all
4123                 processes moved least once.
4124                 this means we can start the search for cycles -
4125                 to be able to return to this state, we should be able to
4126                 run down the counter to 1 again -- which implies a visit to
4127                 the accepting state -- even though the Seed state for this
4128                 search is itself not necessarily accepting
4129 #endif
4130         "                               if ((now._a_t&2) /* A-bit */",
4131         "                               &&  (now._cnt[0] == 1))",
4132         "                                       checkcycles();",
4133         "                       } else",
4134                 "#endif",
4135         "                       if (a_cycles && (trpt->o_pm&2))",
4136         "                               checkcycles();",
4137         "               }",
4138         "#endif",
4139         "       }",
4140         "       if (depth > 0)",
4141         "       {",
4142         "#if NCORE>1 && defined(FULL_TRAIL)",
4143         "               if (upto > 0)",
4144         "               {       Pop_Stack_Tree();",
4145         "               }",
4146         "#endif",
4147         "               goto Up;",
4148         "       }",
4149         "}\n",
4150         "#else",
4151         "void new_state(void) { /* place holder */ }",
4152         "#endif",       /* BFS */
4153         "",
4154         "void",
4155         "spin_assert(int a, char *s, int ii, int tt, Trans *t)",
4156         "{",
4157         "       if (!a && !noasserts)",
4158         "       {       char bad[1024];",
4159         "               strcpy(bad, \"assertion violated \");",
4160         "               if (strlen(s) > 1000)",
4161         "               {       strncpy(&bad[19], (const char *) s, 1000);",
4162         "                       bad[1019] = '\\0';",
4163         "               } else",
4164         "                       strcpy(&bad[19], s);",
4165         "               uerror(bad);",
4166         "       }",
4167         "}",
4168         "#ifndef NOBOUNDCHECK",
4169         "int",
4170         "Boundcheck(int x, int y, int a1, int a2, Trans *a3)",
4171         "{",
4172         "       spin_assert((x >= 0 && x < y), \"- invalid array index\",",
4173         "               a1, a2, a3);",
4174         "       return x;",
4175         "}",
4176         "#endif",
4177         "int do_hashgen = 0;",
4178         "void",
4179         "wrap_stats(void)",
4180         "{",
4181         "       if (nShadow>0)",
4182         "         printf(\"%%9.8g states, stored (%%g visited)\\n\",",
4183         "                       nstates - nShadow, nstates);",
4184         "       else",
4185         "         printf(\"%%9.8g states, stored\\n\", nstates);",
4186         "#ifdef BFS_PAR",
4187         "       if (bfs_punt > 0)",
4188         "       printf(\"%%9.8g states lost (lack of queue memory)\\n\", (double) bfs_punt);",
4189         "#endif",
4190         "#ifdef BFS",
4191         "       #if SYNC",
4192         "       printf(\"       %%8g nominal states (- rv and atomic)\\n\", nstates-midrv-nlinks+revrv);",
4193         "       printf(\"       %%8g rvs succeeded\\n\", midrv-failedrv);",
4194         "       #else",
4195         "       printf(\"       %%8g nominal states (stored-atomic)\\n\", nstates-nlinks);",
4196         "       #endif",
4197         "       #ifdef DEBUG",
4198         "       printf(\"       %%8g midrv\\n\", midrv);",
4199         "       printf(\"       %%8g failedrv\\n\", failedrv);",
4200         "       printf(\"       %%8g revrv\\n\", revrv);",
4201         "       #endif",
4202         "#endif",
4203         "       printf(\"%%9.8g states, matched\\n\", truncs);",
4204         "#ifdef CHECK",
4205         "       printf(\"%%9.8g matches within stack\\n\",truncs2);",
4206         "#endif",
4207         "       if (nShadow>0)",
4208         "       printf(\"%%9.8g transitions (= visited+matched)\\n\",",
4209         "               nstates+truncs);",
4210         "       else",
4211         "       printf(\"%%9.8g transitions (= stored+matched)\\n\",",
4212         "               nstates+truncs);",
4213         "       printf(\"%%9.8g atomic steps\\n\", nlinks);",
4214         "       if (nlost) printf(\"%%g lost messages\\n\", (double) nlost);",
4215         "",
4216         "#ifndef BITSTATE",
4217         "       #ifndef MA",
4218         "       printf(\"hash conflicts: %%9.8g (resolved)\\n\", hcmp);",
4219         "               #if !defined(AUTO_RESIZE) && !defined(BFS_PAR)",
4220         "       if (hcmp > (double) (1<<ssize))",
4221         "       {  printf(\"hint: increase hashtable-size (-w) to reduce runtime\\n\");",
4222         "       }",
4223         "               #endif",
4224         "               #if defined(BFS_PAR) && defined(HC)",
4225         "       { double fp = (100. * (double) nstates)/((double) ((ulong) (1<<ssize)));",
4226         "         int fi = 0;",
4227         "               printf(\"the hash table is %%3.3g %%%% filled\", fp);",
4228         "               if (fp > 1.0)",
4229         "               {       fp = 100. / fp;",
4230         "                       while (fp > 2.) { fi++; fp /= 2.; }",
4231         "                       if (fi > 0)",
4232         "                       {       printf(\" (hint: rerun with -w%%d to reduce runtime)\",",
4233         "                               ssize-fi);",
4234         "               }       }",
4235         "               printf(\"\\n\");",
4236         "       }",
4237         "               #endif",
4238         "       #endif",
4239         "#else",
4240                 "#ifdef CHECK",
4241                 "       printf(\"%%8g states allocated for dfs stack\\n\", ngrabs);",
4242                 "#endif",
4243         "       if (udmem)",
4244         "       printf(\"\\nhash factor: %%4g (best if > 100.)\\n\\n\",",
4245         "               (double)(((double) udmem) * 8.0) / (double) nstates);",
4246         "       else",
4247         "       printf(\"\\nhash factor: %%4g (best if > 100.)\\n\\n\",",
4248         "               ((double)(((ulong)1)<<(ssize-10)) / (double) nstates) * 1024.0);",
4249                         /* the -10 and *1024 stuff is to avoid overflow */
4250         "       printf(\"bits set per state: %%u (-k%%u)\\n\", hfns, hfns);",
4251         "       if (do_hashgen)",
4252         "       printf(\"hash polynomial used: 0x%%.8x\\n\", HASH_CONST[HASH_NR]);",
4253         "       if (s_rand != 12345)",
4254         "       printf(\"random seed used: %%u\\n\", (uint) (s_rand-1));",
4255         "#endif",
4256         "#if defined(BFS_DISK) && !defined(BFS_PAR)",
4257         "       printf(\"bfs disk reads: %%ld writes %%ld -- diff %%ld\\n\",",
4258         "               bfs_dsk_reads, bfs_dsk_writes, bfs_dsk_writes-bfs_dsk_reads);",
4259         "       if (bfs_dsk_read  >= 0) (void) close(bfs_dsk_read);",
4260         "       if (bfs_dsk_write >= 0) (void) close(bfs_dsk_write);",
4261         "       (void) unlink(\"pan_bfs_dsk.tmp\");",
4262         "#endif",
4263         "}",
4264         "",
4265         "void",
4266         "wrapup(void)",
4267         "{      double nr1, nr2, nr3 = 0.0, nr4, nr5 = 0.0;",
4268         "#ifdef BFS_PAR",
4269         "       if (who_am_i != 0)",
4270         "       {       pan_exit(0);",
4271         "       }",
4272         "#endif",
4273         "#if NCORE>1",
4274         "       if (verbose) cpu_printf(\"wrapup -- %%d error(s)\\n\", errors);",
4275         "       if (core_id != 0)",
4276         "       {",
4277         "       #ifdef USE_DISK",
4278         "               void    dsk_stats(void);",
4279         "               dsk_stats();",
4280         "       #endif",
4281         "               if (search_terminated != NULL)",
4282         "               {       *search_terminated |= 2;        /* wrapup */",
4283         "               }",
4284         "               exit(0); /* normal termination, not an error */",
4285         "       }",
4286         "#endif",
4287         "#if !defined(WIN32) && !defined(WIN64)",
4288         "       signal(SIGINT, SIG_DFL);",
4289         "#endif",
4290         "       printf(\"\\n(%%s)\\n\", SpinVersion);",
4291         "       if (!done) printf(\"Warning: Search not completed\\n\");",
4292         "#if defined(BFS_PAR) && !defined(BITSTATE)",
4293         "       if (bfs_punt > 0) printf(\"Warning: Search incomplete\\n\");",
4294         "#endif",
4295         "#ifdef SC",
4296         "       (void) unlink((const char *)stackfile);",
4297         "#endif",
4298         "#ifdef BFS_PAR",
4299         "       printf(\"       + Multi-Core (using %%d cores)\\n\", Cores);",
4300         "       #ifdef BFS_SEP_HASH",
4301         "       printf(\"       + Separate Hash Tables\\n\");",
4302         "       #endif",
4303         "       #ifdef BFS_DISK",
4304         "       printf(\"       + Disk storage\\n\");",
4305         "       #endif",
4306         "#endif",
4307         "#if NCORE>1",
4308         "       if (a_cycles)",
4309         "       {       printf(\"       + Multi-Core (NCORE=%%d)\\n\", NCORE);",
4310         "       } else",
4311         "       {       printf(\"       + Multi-Core (NCORE=%%d -z%%ld)\\n\", NCORE, z_handoff);",
4312         "       }",
4313         "#endif",
4314         "#ifdef BFS",
4315         "       printf(\"       + Breadth-First Search\\n\");",
4316         "#endif",
4317         "#ifndef NOREDUCE",
4318         "       printf(\"       + Partial Order Reduction\\n\");",
4319         "#endif",
4320         "#ifdef PERMUTED",
4321         "       printf(\"       + Process Scheduling Permutation\\n\");",
4322         "#endif",
4323         "#ifdef P_REVERSE",
4324         "       printf(\"       + Reverse Depth-First Search Order\\n\");",
4325         "#endif",
4326         "       if (t_reverse)",
4327         "       printf(\"       + Reverse Transition Ordering\\n\");",
4328         "#ifdef T_RAND",
4329         "       printf(\"       + Randomized Transition Ordering\\n\");",
4330         "#endif",
4331         "#ifdef P_RAND",
4332         "       printf(\"       + Randomized Process Ordering\\n\");",
4333         "#endif",
4334         "#ifdef BCS",
4335         "       printf(\"       + Scheduling Restriction (-L%%d)\\n\", sched_max);",
4336         "#endif",
4337         "#ifdef TRIX",
4338         "       printf(\"       + Tree Index Compression\\n\");",
4339         "#endif",
4340         "#ifdef COLLAPSE",
4341         "       printf(\"       + Compression\\n\");",
4342         "#endif",
4343         "#ifdef MA",
4344         "       printf(\"       + Graph Encoding (-DMA=%%d)\\n\", MA);",
4345         "  #ifdef R_XPT",
4346         "       printf(\"         Restarted from checkpoint %%s.xpt\\n\", PanSource);",
4347         "  #endif",
4348         "#endif",
4349         "#ifdef CHECK",
4350         "  #ifdef FULLSTACK",
4351         "       printf(\"       + FullStack Matching\\n\");",
4352         "  #endif",
4353         "  #ifdef CNTRSTACK",
4354         "       printf(\"       + CntrStack Matching\\n\");",
4355         "  #endif",
4356         "#endif",
4357         "#ifdef PERMUTED",
4358         "       if (reversing & 2)",
4359         "       {       if (p_reorder == set_permuted)",
4360         "               {       printf(\"       + Permuted\\n\");",
4361         "               }",
4362         "               if (p_reorder == set_reversed)",
4363         "               {       printf(\"       + Reversed\\n\");",
4364         "               }",
4365         "               if (p_reorder == set_rotated)",
4366         "               {       printf(\"       + Rotated %%d\\n\", p_rotate);",
4367         "               }",
4368         "               if (p_reorder == set_randrot)",
4369         "               {       printf(\"       + RandRotated\\n\");",
4370         "       }       }",
4371         "#endif",
4372         "#ifdef BITSTATE",
4373         "       printf(\"\\nBit statespace search for:\\n\");",
4374         "#else",
4375         "  #ifdef HC",
4376         "       printf(\"\\nHash-Compact %%d search for:\\n\", HC);",
4377         "  #else",
4378         "       printf(\"\\nFull statespace search for:\\n\");",
4379         "  #endif",
4380         "#endif",
4381         "#ifdef EVENT_TRACE",
4382         "#ifdef NEGATED_TRACE",
4383         "       printf(\"\tnotrace assertion  \t+\\n\");",
4384         "#else",
4385         "       printf(\"\ttrace assertion    \t+\\n\");",
4386         "#endif",
4387         "#endif",
4388         "#ifdef VERI",
4389         "       printf(\"\tnever claim         \t+\");",
4390         "       printf(\" (%%s)\\n\", procname[((Pclaim *)pptr(0))->_t]);",
4391         "       printf(\"\tassertion violations\t\");",
4392         "       if (noasserts)",
4393         "               printf(\"- (disabled by -A flag)\\n\");",
4394         "       else",
4395         "               printf(\"+ (if within scope of claim)\\n\");",
4396         "#else",
4397                 "#ifdef NOCLAIM",
4398         "       printf(\"\tnever claim         \t- (not selected)\\n\");",
4399                 "#else",
4400         "       printf(\"\tnever claim         \t- (none specified)\\n\");",
4401                 "#endif",
4402         "       printf(\"\tassertion violations\t\");",
4403         "       if (noasserts)",
4404         "               printf(\"- (disabled by -A flag)\\n\");",
4405         "       else",
4406         "               printf(\"+\\n\");",
4407         "#endif",
4408         "#ifndef SAFETY",
4409                 "#ifdef NP",
4410         "       printf(\"\tnon-progress cycles \t\");",
4411                 "#else",
4412         "       printf(\"\tacceptance   cycles \t\");",
4413                 "#endif",
4414         "       if (a_cycles)",
4415         "               printf(\"+ (fairness %%sabled)\\n\",",
4416         "                       fairness?\"en\":\"dis\");",
4417         "       else printf(\"- (not selected)\\n\");",
4418         "#else",
4419         "       #if !defined(BFS_PAR) || !defined(L_BOUND)",
4420         "       printf(\"\tcycle checks       \t- (disabled by -DSAFETY)\\n\");",
4421         "       #else",
4422         "       printf(\"\tcycle checks       \t+ (bound %%d)\\n\", L_bound);",
4423         "       #endif",
4424         "#endif",
4425         "#ifdef VERI",
4426         "       printf(\"\tinvalid end states\t- \");",
4427         "       printf(\"(disabled by \");",
4428         "       if (noends)",
4429         "               printf(\"-E flag)\\n\\n\");",
4430         "       else",
4431         "               printf(\"never claim)\\n\\n\");",
4432         "#else",
4433         "       printf(\"\tinvalid end states\t\");",
4434         "       if (noends)",
4435         "               printf(\"- (disabled by -E flag)\\n\\n\");",
4436         "       else",
4437         "               printf(\"+\\n\\n\");",
4438         "#endif",
4439         "       printf(\"State-vector %%d byte, depth reached %%ld\", hmax,",
4440         "#if NCORE>1",
4441         "                                       (nr_handoffs * z_handoff) +",
4442         "#endif",
4443         "                                       mreached);",
4444         "       printf(\", errors: %%d\\n\", errors);",
4445         "       fflush(stdout);",
4446         "#ifdef MA",
4447         "       if (done)",
4448         "       {       extern void dfa_stats(void);",
4449         "               if (maxgs+a_cycles+2 < MA)",
4450         "               printf(\"MA stats: -DMA=%%d is sufficient\\n\",",
4451         "                       maxgs+a_cycles+2);",
4452         "               dfa_stats();",
4453         "       }",
4454         "#endif",
4455         "       wrap_stats();",
4456         "#ifdef CHECK",
4457         "       printf(\"stackframes: %%d/%%d\\n\\n\", smax, svmax);",
4458         "       printf(\"stats: fa %%ld, fh %%ld, zh %%ld, zn %%ld - \",",
4459         "               Fa, Fh, Zh, Zn);",
4460         "       printf(\"check %%ld holds %%ld\\n\", Ccheck, Cholds);",
4461         "       printf(\"stack stats: puts %%ld, probes %%ld, zaps %%ld\\n\",",
4462         "               PUT, PROBE, ZAPS);",
4463         "#else",
4464         "       printf(\"\\n\");",
4465         "#endif",
4466         "",
4467         "#if !defined(BITSTATE) && defined(NOCOMP)",
4468         "       if (!verbose) { goto jump_here; }",     /* added 5.2.0 */
4469         "#endif",
4470         "",
4471         "#if 1",        /* omitted 5.2.0:  defined(BITSTATE) || !defined(NOCOMP) */
4472         "       nr1 = (nstates-nShadow)*",
4473         "             (double)(hmax+sizeof(H_el)-sizeof(unsigned));",
4474         "       #ifdef BFS",
4475         "       nr2 = 0.0;",
4476         "       #else",
4477         "       nr2 = (double) ((maxdepth+3)*sizeof(Trail));",
4478         "       #endif",
4479
4480         "       #ifndef BITSTATE",
4481                         "#if !defined(MA) || defined(COLLAPSE)",
4482         "       nr3 = (double) (ONE_L<<ssize)*sizeof(H_el *);",
4483                         "#endif",
4484         "       #else",
4485         "       if (udmem)",
4486         "               nr3 = (double) (udmem);",
4487         "       else",
4488         "               nr3 = (double) (ONE_L<<(ssize-3));",
4489                         "#ifdef CNTRSTACK",
4490         "       nr5 = (double) (ONE_L<<(ssize-3));",
4491                         "#endif",
4492                         "#ifdef FULLSTACK",
4493         "       nr5 = (double) (maxdepth*sizeof(H_el *));",
4494                         "#endif",
4495         "       #endif",
4496
4497         "       nr4 = (double) (svmax * (sizeof(Svtack) + hmax))",
4498         "           + (double) (smax  * (sizeof(_Stack) + Maxbody * sizeof(char)));",
4499                 "#ifndef MA",
4500         "       if (1 /* verbose || memcnt < nr1+nr2+nr3+nr4+nr5 */)",
4501                 "#endif",
4502         "       { double remainder = memcnt;",
4503         "         double tmp_nr = memcnt-nr3-nr4-(nr2-fragment)-nr5;",
4504         "",
4505         "       #if NCORE>1 && !defined(SEP_STATE)",
4506         "               tmp_nr -= ((double) NCORE * LWQ_SIZE) + GWQ_SIZE;",
4507         "       #endif",
4508         "               if (tmp_nr < 0.0) tmp_nr = 0.;",
4509         "               printf(\"Stats on memory usage (in Megabytes):\\n\");",
4510         "               printf(\"%%9.3f\tequivalent memory usage for states\",",
4511         "                       nr1/1048576.); /* 1024*1024=1048576 */",
4512         "               printf(\" (stored*(State-vector + overhead))\\n\");",
4513         "       #if NCORE>1 && !defined(WIN32) && !defined(WIN64)",
4514         "               printf(\"%%9.3f\tshared memory reserved for state storage\\n\",",
4515         "                       mem_reserved/1048576.);",
4516         "               #ifdef SEP_HEAP",
4517         "               printf(\"\t\tin %%d local heaps of %%7.3f MB each\\n\",",
4518         "                       NCORE, mem_reserved/(NCORE*1048576.));",
4519         "               #endif",
4520         "               printf(\"\\n\");",
4521         "       #endif",
4522         "       #ifdef BITSTATE",
4523         "               if (udmem)",
4524         "                       printf(\"%%9.3f\tmemory used for hash array (-M%%ld)\\n\",",
4525         "                       nr3/1048576., udmem/(1024L*1024L));",
4526         "               else",
4527         "                       printf(\"%%9.3f\tmemory used for hash array (-w%%d)\\n\",",
4528         "                       nr3/1048576., ssize);",
4529         "               if (nr5 > 0.0)",
4530         "               printf(\"%%9.3f\tmemory used for bit stack\\n\",",
4531         "                       nr5/1048576.);",
4532         "               remainder = remainder - nr3 - nr5;",
4533         "       #else",
4534         "               #ifndef USE_TDH",
4535         "                       printf(\"%%9.3f\tactual memory usage for states\",",
4536         "                               tmp_nr/1048576.);",
4537         "                       remainder -= tmp_nr;",
4538         "                       if (tmp_nr > 0.)",
4539         "                       {       if (tmp_nr < nr1) ",
4540         "                               {       printf(\" (compression: %%.2f%%%%)\\n\",",
4541         "                                               (100.0*tmp_nr)/nr1);",
4542         "                               } else",
4543         "                               {       printf(\"\\n\");",
4544         "                               }",
4545         "                       } else",
4546         "                       {       printf(\" (less than 1k)\\n\");",
4547         "                       }",
4548         "                       #ifndef MA",
4549         "                       if (tmp_nr > 0. && tmp_nr < nr1)",
4550         "                       {       printf(\"         \tstate-vector as stored = %%.0f byte\",",
4551         "                               (tmp_nr)/(nstates-nShadow) -",
4552         "                               (double) (sizeof(H_el) - sizeof(unsigned)));",
4553         "                               printf(\" + %%ld byte overhead\\n\",",
4554         "                               (long int) sizeof(H_el)-sizeof(unsigned));",
4555         "                       }",
4556         "                       #endif",
4557         "               #endif",
4558         "               #if !defined(MA) || defined(COLLAPSE)",
4559         "                       #ifdef BFS_PAR",
4560         "                               printf(\"%%9.3f\tshared memory used for hash table (-w%%d)\\n\",",
4561         "                               ((double) bfs_pre_allocated)/1048576., ssize);",
4562         "                       #else",
4563         "                               printf(\"%%9.3f\tmemory used for hash table (-w%%d)\\n\",",
4564         "                                       nr3/1048576., ssize);",
4565         "                               remainder -= nr3;",
4566         "                       #endif",
4567         "               #endif",
4568         "       #endif",
4569         "       #ifndef BFS",
4570         "               printf(\"%%9.3f\tmemory used for DFS stack (-m%%ld)\\n\",",
4571         "                       nr2/1048576., maxdepth);",
4572         "               remainder -= nr2;",
4573         "       #endif",
4574         "       #if NCORE>1",
4575         "               remainder -= ((double) NCORE * LWQ_SIZE) + GWQ_SIZE;",
4576         "               printf(\"%%9.3f\tshared memory used for work-queues\\n\",",
4577         "                       (GWQ_SIZE + (double) NCORE * LWQ_SIZE) /1048576.);",
4578         "               printf(\"\t\tin %%d queues of %%7.3f MB each\",",
4579         "                       NCORE, (double) LWQ_SIZE /1048576.);",
4580         "               #ifndef NGQ",
4581         "               printf(\" + a global q of %%7.3f MB\\n\",",
4582         "                       (double) GWQ_SIZE / 1048576.);",
4583         "               #else",
4584         "               printf(\"\\n\");",
4585         "               #endif",
4586         "       #endif",
4587         "               if (remainder - fragment > 1048576.)",
4588         "               {       printf(\"%%9.3f\tother (proc and chan stacks)\\n\",",
4589         "                       (remainder-fragment)/1048576.);",
4590         "               }",
4591         "               if (fragment > 1048576.)",
4592         "               {       printf(\"%%9.3f\tmemory lost to fragmentation\\n\",",
4593         "                       fragment/1048576.);",
4594         "               }",
4595         "       #ifdef BFS_PAR",
4596         "               printf(\"%%9.3f\ttotal non-shared memory usage\\n\\n\",",
4597         "                       memcnt/1048576.);",
4598         "       #else",
4599         "               printf(\"%%9.3f\ttotal actual memory usage\\n\\n\",",
4600         "                       memcnt/1048576.);",
4601         "       #endif",
4602         "       }",
4603         "       #ifndef MA",
4604         "       else",
4605         "       #endif",
4606         "#endif",
4607
4608         "#if !defined(BITSTATE) && defined(NOCOMP)",
4609         "jump_here:",
4610         "#endif",
4611         "#ifndef MA",
4612         "       printf(\"%%9.3f\tmemory usage (Mbyte)\\n\",",
4613         "               memcnt/1048576.);",
4614         "#endif",
4615         "#ifdef BFS_PAR",
4616         "       bfs_report_mem();",
4617         "#else",
4618         "       printf(\"\\n\");",
4619         "#endif",
4620         "#ifdef COLLAPSE",
4621         "       printf(\"nr of templates: [ 0:globals 1:chans 2:procs ]\\n\");",
4622         "       printf(\"collapse counts: [ \");",
4623         "       { int i; for (i = 0; i < 256+2; i++)",
4624         "               if (ncomps[i] != 0)",
4625         "                       printf(\"%%d:%%lu \", i, ncomps[i]);",
4626         "               printf(\"]\\n\");",
4627         "       }",
4628         "#endif",
4629         "       #ifdef TRIX",
4630         "       if (verbose)",
4631         "       {       int i;",
4632         "               printf(\"TRIX counts:\\n\");",
4633         "               printf(\"  processes: \");",
4634         "               for (i = 0; i < MAXPROC; i++)",
4635         "                       if (_p_count[i] != 0)",
4636         "                       {       printf(\"%%3d:%%ld \",",
4637         "                                       i, _p_count[i]);",
4638         "                       }",
4639         "               printf(\"\\n  channels : \");",
4640         "               for (i = 0; i < MAXQ; i++)",
4641         "                       if (_c_count[i] != 0)",
4642         "                       {       printf(\"%%3d:%%ld \",",
4643         "                                       i, _c_count[i]);",
4644         "                       }",
4645         "               printf(\"\\n\\n\");",
4646         "       }",
4647         "       #endif",
4648
4649         "       if ((done || verbose) && !no_rck) do_reach();",
4650         "#ifdef PEG",
4651         "       { int i;",
4652         "         printf(\"\\nPeg Counts (transitions executed):\\n\");",
4653         "         for (i = 1; i < NTRANS; i++)",
4654         "         {     if (peg[i]) putpeg(i, peg[i]);",
4655         "       } }",
4656         "#endif",
4657         "#ifdef VAR_RANGES",
4658         "       dumpranges();",
4659         "#endif",
4660         "#ifdef SVDUMP",
4661         "       if (vprefix > 0) close(svfd);",
4662         "#endif",
4663         "#ifdef LOOPSTATE",
4664         "       printf(\"%%g loopstates hit\\n\", cnt_loops);",
4665         "#endif",
4666         "#ifdef NSUCC",
4667         "       dump_succ();",
4668         "#endif",
4669         "#if NCORE>1 && defined(T_ALERT)",
4670         "       crash_report();",
4671         "#endif",
4672         "#ifndef BFS_PAR",
4673         "       pan_exit(0);",
4674         "#endif",
4675         "}\n",
4676         "void",
4677         "stopped(int arg)",
4678         "{",
4679         "#ifdef BFS_PAR",
4680         "       bfs_shutdown(\"interrupted\");",
4681         "#endif",
4682         "       printf(\"Interrupted\\n\");",
4683         "#if NCORE>1",
4684         "       was_interrupted = 1;",
4685         "#endif",
4686         "       wrapup();",
4687         "       pan_exit(0);",
4688         "}",
4689         "",
4690         "/*",
4691         " * super fast hash, based on Paul Hsieh's function",
4692         " * http://www.azillionmonkeys.com/qed/hash.html",
4693         " */",
4694         "#include <stdint.h>",  /* for uint32_t etc */
4695         " #undef get16bits",
4696         " #if defined(__GNUC__) && defined(__i386__)",
4697         "       #define get16bits(d) (*((const uint16_t *) (d)))",
4698         " #else",
4699         "       #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\\",
4700         "                              +(uint32_t)(((const uint8_t *)(d))[0]) )",
4701         " #endif",
4702         "",
4703         "void",
4704         "d_sfh(uchar *s, int len)",     /* sets one 32-bit number, in K1 */
4705         "{      uint32_t h = len, tmp;",
4706         "       int rem;",
4707         "",
4708         "       rem = len & 3;",
4709         "       len >>= 2;",
4710         "",
4711         "       for ( ; len > 0; len--)",
4712         "       {       h  += get16bits(s);",
4713         "               tmp = (get16bits(s+2) << 11) ^ h;",
4714         "               h   = (h << 16) ^ tmp;",
4715         "               s  += 2*sizeof(uint16_t);",
4716         "               h  += h >> 11;",
4717         "       }",
4718         "       switch (rem) {",
4719         "       case 3: h += get16bits(s);",
4720         "               h ^= h << 16;",
4721         "               h ^= s[sizeof(uint16_t)] << 18;",
4722         "               h += h >> 11;",
4723         "               break;",
4724         "       case 2: h += get16bits(s);",
4725         "               h ^= h << 11;",
4726         "               h += h >> 17;",
4727         "               break;",
4728         "       case 1: h += *s;",
4729         "               h ^= h << 10;",
4730         "               h += h >> 1;",
4731         "               break;",
4732         "       }",
4733         "       h ^= h << 3;",
4734         "       h += h >> 5;",
4735         "       h ^= h << 4;",
4736         "       h += h >> 17;",
4737         "       h ^= h << 25;",
4738         "       h += h >> 6;",
4739         "",
4740         "       K1 = h;",
4741         "}",
4742         "",
4743         "#if WS>4",
4744         "/* 64-bit Jenkins hash, 1997",
4745         " * http://burtleburtle.net/bob/c/lookup8.c",
4746         " */",
4747         "#define mix(a,b,c) \\",
4748         "{ a -= b; a -= c; a ^= (c>>43); \\",
4749         "  b -= c; b -= a; b ^= (a<<9);  \\",
4750         "  c -= a; c -= b; c ^= (b>>8);  \\",
4751         "  a -= b; a -= c; a ^= (c>>38); \\",
4752         "  b -= c; b -= a; b ^= (a<<23); \\",
4753         "  c -= a; c -= b; c ^= (b>>5);  \\",
4754         "  a -= b; a -= c; a ^= (c>>35); \\",
4755         "  b -= c; b -= a; b ^= (a<<49); \\",
4756         "  c -= a; c -= b; c ^= (b>>11); \\",
4757         "  a -= b; a -= c; a ^= (c>>12); \\",
4758         "  b -= c; b -= a; b ^= (a<<18); \\",
4759         "  c -= a; c -= b; c ^= (b>>22); \\",
4760         "}",
4761         "#else",
4762         "/* 32-bit Jenkins hash, 2006",
4763         " * http://burtleburtle.net/bob/c/lookup3.c",
4764         " */",
4765         "#define rot(x,k)       (((x)<<(k))|((x)>>(32-(k))))",
4766         "",
4767         "#define mix(a,b,c) \\",
4768         "{ a -= c;  a ^= rot(c, 4);  c += b; \\",
4769         "  b -= a;  b ^= rot(a, 6);  a += c; \\",
4770         "  c -= b;  c ^= rot(b, 8);  b += a; \\",
4771         "  a -= c;  a ^= rot(c,16);  c += b; \\",
4772         "  b -= a;  b ^= rot(a,19);  a += c; \\",
4773         "  c -= b;  c ^= rot(b, 4);  b += a; \\",
4774         "}",
4775         "",
4776         "#define final(a,b,c) \\",
4777         "{ c ^= b; c -= rot(b,14); \\",
4778         "  a ^= c; a -= rot(c,11); \\",
4779         "  b ^= a; b -= rot(a,25); \\",
4780         "  c ^= b; c -= rot(b,16); \\",
4781         "  a ^= c; a -= rot(c,4);  \\",
4782         "  b ^= a; b -= rot(a,14); \\",
4783         "  c ^= b; c -= rot(b,24); \\",
4784         "}",
4785         "#endif",
4786         "",
4787         "void",
4788         "d_hash(uchar *kb, int nbytes)", /* sets two 64-bit or 32-bit nrs, depending on WS */
4789         "{      uint8_t  *bp;",
4790         "#if WS>4",
4791         "       uint64_t a = 0, b, c, n;",
4792         "       const uint64_t *k = (uint64_t *) kb;",
4793         "#else",
4794         "       uint32_t a = 0, b, c, n;",
4795         "       const uint32_t *k = (uint32_t *) kb;",
4796         "#endif",
4797         "       n = nbytes/WS;  /* nr of words */",
4798         "       /* extend to multiple of words, if needed */",
4799         "       a = WS - (nbytes %% WS);",
4800         "       if (a > 0 && a < WS)",
4801         "       {       n++;",
4802         "               bp = kb + nbytes;",
4803         "               switch (a) {",
4804         "#if WS>4",
4805         "               case 7: *bp++ = 0; /* fall thru */",
4806         "               case 6: *bp++ = 0; /* fall thru */",
4807         "               case 5: *bp++ = 0; /* fall thru */",
4808         "               case 4: *bp++ = 0; /* fall thru */",
4809         "#endif",
4810         "               case 3: *bp++ = 0; /* fall thru */",
4811         "               case 2: *bp++ = 0; /* fall thru */",
4812         "               case 1: *bp   = 0;",
4813         "               case 0: break;",
4814         "       }       }",
4815         "#if WS>4",
4816         "       b = HASH_CONST[HASH_NR];",
4817         "       c = 0x9e3779b97f4a7c13LL; /* arbitrary value */",
4818         "       while (n >= 3)",
4819         "       {       a += k[0];",
4820         "               b += k[1];",
4821         "               c += k[2];",
4822         "               mix(a,b,c);",
4823         "               n -= 3;",
4824         "               k += 3;",
4825         "       }",
4826         "       c += (((uint64_t) nbytes)<<3);",
4827         "       switch (n) {",
4828         "       case 2: b += k[1];",
4829         "       case 1: a += k[0];",
4830         "       case 0: break;",
4831         "       }",
4832         "       mix(a,b,c);",
4833         "#else", /* 32 bit version: */
4834         "       a = c = 0xdeadbeef + (n<<2);",
4835         "       b = HASH_CONST[HASH_NR];",
4836         "       while (n > 3)",
4837         "       {       a += k[0];",
4838         "               b += k[1];",
4839         "               c += k[2];",
4840         "               mix(a,b,c);",
4841         "               n -= 3;",
4842         "               k += 3;",
4843         "       }",
4844         "       switch (n) { ",
4845         "       case 3: c += k[2];",
4846         "       case 2: b += k[1];",
4847         "       case 1: a += k[0];",
4848         "               final(a,b,c);",
4849         "       case 0: break;",
4850         "       }",
4851         "#endif",
4852         "       j1_spin = c&nmask; j3_spin = a&7; /* 1st bit */",
4853         "       j2_spin = b&nmask; j4_spin = (a>>3)&7; /* 2nd bit */",
4854         "       K1 = c; K2 = b;",
4855         "}",
4856         "",
4857         "#if defined(MURMUR) && (WS==8)",
4858         "/* public-domain, 64-bit MurmurHash3, by Austin Appleby */",
4859         "/*  https://code.google.com/p/smhasher/wiki/MurmurHash3 */",
4860         "void",
4861         "m_hash(uchar *v, int len)",
4862         "{      uint8_t *bp, *data = (uint8_t*) v;",
4863         "       int i, nblocks = len / 16;",
4864         "",
4865         "       uint64_t h1 = HASH_CONST[HASH_NR];",
4866         "       uint64_t h2 = 0x9e3779b97f4a7c13LL;",
4867         "",
4868         "       uint64_t c1 = 0x87c37b91114253d5;",
4869         "       uint64_t c2 = 0x4cf5ad432745937f;",
4870         "",
4871         "       uint64_t *blocks = (uint64_t *)(data);",
4872         "",
4873         "       /* guarantee a multiple of 16 bytes */",
4874         "       i = 16 - (len %% 16);",
4875         "       if (i > 0 && i < 16)",
4876         "       {       nblocks++;",
4877         "               bp = v + len;",
4878         "               switch (i) {",
4879         "               case 15: *bp++ = 0; /* fall thru */",
4880         "               case 14: *bp++ = 0;",
4881         "               case 13: *bp++ = 0;",
4882         "               case 12: *bp++ = 0;",
4883         "               case 11: *bp++ = 0;",
4884         "               case 10: *bp++ = 0;",
4885         "               case  9: *bp++ = 0;",
4886         "               case  8: *bp++ = 0;",
4887         "               case  7: *bp++ = 0;",
4888         "               case  6: *bp++ = 0;",
4889         "               case  5: *bp++ = 0;",
4890         "               case  4: *bp++ = 0;",
4891         "               case  3: *bp++ = 0;",
4892         "               case  2: *bp++ = 0;",
4893         "               case  1: *bp   = 0;",
4894         "               case  0: break;",
4895         "       }       }",
4896         "",
4897         "       for (i = 0; i < nblocks; i++)",
4898         "       {       uint64_t k1 = blocks[i*2];",
4899         "               uint64_t k2 = blocks[i*2+1];",
4900         "",
4901         "               k1 *= c1;",
4902         "               k1 = (k1 << 31) | (k1 >> 33);",
4903         "               k1 *= c2;",
4904         "               h1 ^= k1;",
4905         "",
4906         "               h1 = (h1 << 27) | (h1 >> 37);",
4907         "               h1 += h2;",
4908         "               h1 = h1 * 5 + 0x52dce729;",
4909         "",
4910         "               k2 *= c2;",
4911         "               k2 = (k2 << 33) | (k2 >> 31);",
4912         "               k2 *= c1;",
4913         "               h2 ^= k2;",
4914         "",
4915         "               h2 = (h2 << 31) | (h2 >> 33);",
4916         "               h2 += h1;",
4917         "               h2 = h2 * 5 + 0x38495ab5;",
4918         "       }",
4919         "",
4920         "       uint8_t *tail = (uint8_t*)(data + (nblocks * 16));",
4921         "",
4922         "       uint64_t k1 = 0;",
4923         "       uint64_t k2 = 0;",
4924         "",
4925         "       switch(len & 15) {",
4926         "       case 15: k2 ^= ((uint64_t) tail[14]) << 48; break;",
4927         "       case 14: k2 ^= ((uint64_t) tail[13]) << 40; break;",
4928         "       case 13: k2 ^= ((uint64_t) tail[12]) << 32; break;",
4929         "       case 12: k2 ^= ((uint64_t) tail[11]) << 24; break;",
4930         "       case 11: k2 ^= ((uint64_t) tail[10]) << 16; break;",
4931         "       case 10: k2 ^= ((uint64_t) tail[ 9]) << 8; break;",
4932         "       case  9: k2 ^= ((uint64_t) tail[ 8]) << 0; break;",
4933         "                k2 *= c2;",
4934         "                k2 = (k2 << 33) | (k2 >> 31);",
4935         "                k2 *= c1;",
4936         "                h2 ^= k2; break;",
4937         "       case  8: k1 ^= ((uint64_t) tail[7]) << 56; break;",
4938         "       case  7: k1 ^= ((uint64_t) tail[6]) << 48; break;",
4939         "       case  6: k1 ^= ((uint64_t) tail[5]) << 40; break;",
4940         "       case  5: k1 ^= ((uint64_t) tail[4]) << 32; break;",
4941         "       case  4: k1 ^= ((uint64_t) tail[3]) << 24; break;",
4942         "       case  3: k1 ^= ((uint64_t) tail[2]) << 16; break;",
4943         "       case  2: k1 ^= ((uint64_t) tail[1]) << 8; break;",
4944         "       case  1: k1 ^= ((uint64_t) tail[0]) << 0; break;",
4945         "                k1 *= c1;",
4946         "                k1 = (k1 << 31) | (k1 >> 33);",
4947         "                k1 *= c2;",
4948         "                h1 ^= k1;",
4949         "       };",
4950         "",
4951         "       h1 ^= len; h2 ^= len;",
4952         "       h1 += h2;",
4953         "       h2 += h1;",
4954         "       h1 ^= h1 >> 33;",
4955         "       h1 *= 0xff51afd7ed558ccd;",
4956         "       h1 ^= h1 >> 33;",
4957         "       h1 *= 0xc4ceb9fe1a85ec53;",
4958         "       h1 ^= h1 >> 33;",
4959         "       h2 ^= h2 >> 33;",
4960         "       h2 *= 0xff51afd7ed558ccd;",
4961         "       h2 ^= h2 >> 33;",
4962         "       h2 *= 0xc4ceb9fe1a85ec53;",
4963         "       h2 ^= h2 >> 33;",
4964         "       h1 += h2;",
4965         "       h2 += h1;",
4966         "",
4967         "       j1_spin = h1&nmask; j3_spin = (h1>>48)&7;",
4968         "       j2_spin = h2&nmask; j4_spin = (h2>>48)&7;",
4969         "       K1 = h1; K2 = h2;",
4970         "}",
4971         "#endif",
4972         "",
4973         "void",
4974         "s_hash(uchar *cp, int om)",    /* uses either d_sfh (1x32bit), or d_hash (2x64bit) */
4975         "{",                            /* depending on ssize ie the -w parameter */
4976         "       hasher(cp, om);         /* sets K1 */",
4977         "#ifdef BITSTATE",
4978         "       if (S_Tab == H_tab)",   /* state stack in bitstate search */
4979         "               j1_spin = K1 %% omaxdepth;",
4980         "       else",
4981         "#endif",
4982         "       if (ssize < 8*WS)",
4983         "               j1_spin = K1&mask;",
4984         "       else",
4985         "               j1_spin = K1;",
4986         "}",
4987         "#ifndef RANDSTOR",
4988         "int *prerand;",
4989         "void",
4990         "inirand(void)",
4991         "{      int i;",
4992         "       srand(s_rand+HASH_NR);",        /* inirand */
4993         "       prerand = (int *) emalloc((omaxdepth+3)*sizeof(int));",
4994         "       for (i = 0; i < omaxdepth+3; i++)",
4995         "       {       prerand[i] = rand();",
4996         "       }",
4997         "}",
4998         "int",
4999         "pan_rand(void)",
5000         "{      if (!prerand) inirand();",
5001         "       return prerand[depth];",
5002         "}",
5003         "#endif",
5004         "",
5005         "void",
5006         "set_masks(void)",
5007         "{",
5008         "       if (WS == 4 && ssize >= 32)",
5009         "       {       mask = 0xffffffff;",
5010         "#ifdef BITSTATE",
5011         "               switch (ssize) {",
5012         "               case 34: nmask = (mask>>1); break;",
5013         "               case 33: nmask = (mask>>2); break;",
5014         "               default: nmask = (mask>>3); break;",
5015         "               }",
5016         "#else",
5017         "               nmask = mask;",
5018         "#endif",
5019         "       } else if (WS == 8)",
5020         "       {       mask = ((ONE_L<<ssize)-1);      /* hash init */",
5021         "#ifdef BITSTATE",
5022         "               nmask = mask>>3;",
5023         "#else",
5024         "               nmask = mask;",
5025         "#endif",
5026         "       } else if (WS != 4)",
5027         "       {       fprintf(stderr, \"pan: wordsize %%ld not supported\\n\", (long int) WS);",
5028         "               exit(1);",
5029         "       } else  /* WS == 4 and ssize < 32 */",
5030         "       {       mask = ((ONE_L<<ssize)-1);      /* hash init */",
5031         "               nmask = (mask>>3);",
5032         "       }",
5033         "}",
5034         "",
5035         "#if defined(AUTO_RESIZE) && !defined(BITSTATE) && !defined(MA)",
5036         "#if NCORE>1",
5037         "       #error cannot combine AUTO_RESIZE with NCORE>1",
5038         "#endif",
5039         "static long reclaim_size;",
5040         "static char *reclaim_mem;",
5041         "static H_el **N_tab;",
5042         "void",
5043         "reverse_capture(H_el *p)",
5044         "{      if (!p) return;",
5045         "       reverse_capture(p->nxt);",
5046         "       /* last element of list moves first */",
5047         "       /* to preserve list-order */",
5048         "       j2_spin = p->m_K1;",
5049         "       if (ssize < 8*WS) /* probably always true */",
5050         "       {       j2_spin &= mask;",
5051         "       }",
5052         "       p->nxt = N_tab[j2_spin];",
5053         "       N_tab[j2_spin] = p;",
5054         "}",
5055         "void",
5056         "resize_hashtable(void)",
5057         "{",
5058         "#ifndef BFS_PAR",      /* ssize and mask/nmask are not in shared mem */
5059         "       if (WS == 4 && ssize >= 27 - 1)",
5060         "#endif",
5061         "       {       return; /* cannot increase further */",
5062         "       }",
5063         "",
5064         "       ssize += 2; /* 4x size @htable ssize */",
5065         "",
5066         "       printf(\"pan: resizing hashtable to -w%%d.. \", ssize);",
5067         "",
5068         "       N_tab = (H_el **) emalloc((ONE_L<<ssize)*sizeof(H_el *));",
5069         "       set_masks();    /* they changed */",
5070         "",
5071         "       for (j1_spin = 0; j1_spin < (ONE_L << (ssize - 2)); j1_spin++)",
5072         "       {       reverse_capture(H_tab[j1_spin]);",
5073         "       }",
5074         "       reclaim_mem = (char *) H_tab;",
5075         "       reclaim_size = (ONE_L << (ssize - 2));",
5076         "       H_tab = N_tab;",
5077         "",
5078         "       printf(\" done\\n\");",
5079         "}",
5080         "#endif",
5081         "#if defined(ZAPH) && defined(BITSTATE)",
5082         "void",
5083         "zap_hashtable(void)",
5084         "{      cpu_printf(\"pan: resetting hashtable\\n\");",
5085         "       if (udmem)",
5086         "       {       memset(SS, 0, udmem);",
5087         "       } else",
5088         "       {       memset(SS, 0, ONE_L<<(ssize-3));",
5089         "       }",
5090         "}",
5091         "#endif",
5092         "",
5093         "#if NCLAIMS>1",
5094         "int",
5095         "find_claim(char *s)",
5096         "{      int i, j;",
5097         "       for (i = 0; strncmp(procname[i], \":np_:\", 5) != 0; i++)",
5098         "       {       if (strcmp(s, procname[i]) == 0)",
5099         "               {       for (j = 0; j < NCLAIMS; j++)",
5100         "                       {       if (spin_c_typ[j] == i)",
5101         "                               {       return j;",
5102         "                       }       }",
5103         "                       break;",
5104         "       }       }",
5105         "       printf(\"pan: error: cannot find claim '%%s'\\n\", s);",
5106         "       exit(1);",
5107         "       return -1; /* unreachable */",
5108         "}",
5109         "#endif",
5110         "",
5111         "#if defined(BFS_PAR) && defined(BFS_SEP_HASH)",
5112         "int    /* to avoid having to include <math.h> and compile with -lm */",
5113         "blog2(int n)   /* n >= 1 */",
5114         "{      int m=1, r=2;",
5115         "       if (n == 1) { return 0; }",
5116         "       if (n == 2) { return 1; }",
5117         "       while (n > r) { m++; r *= 2; }",
5118         "       return m;",
5119         "}",
5120         "#endif",
5121         "",
5122         "uint pp[33];",
5123         "",
5124         "uint ",
5125         "mul(uint a, uint b, uint p)",
5126         "{      int c = 0;",
5127         "       while (a)",
5128         "       {       if (a&1)",
5129         "               {       a ^= 1;",
5130         "                       c ^= b;",
5131         "               }",
5132         "               a = (a>>1);",
5133         "               if (b & 0x80000000)",
5134         "               {       b += b;",
5135         "                       b ^= p;",
5136         "               } else",
5137         "               {       b += b;",
5138         "       }       }",
5139         "       return c;",
5140         "}",
5141         "",
5142         "uint",
5143         "ppow(int n, uint p)",
5144         "{      uint t = 1; int i;",
5145         "       for (i = 0; i < 32; i++)",
5146         "       {       if (n & (1<<i))",
5147         "               {       t = mul(t, pp[i], p);",
5148         "       }       }",
5149         "       return t;",
5150         "}",
5151         "",
5152         "void",
5153         "hashgen(void)  /* courtesy Jim Reeds, 1995 */",
5154         "{      uint x, y, p; int i, cnt;",
5155         "       int ff[5] = { 3, 5, 17, 257, 65537 };",
5156         "       int nn[5];",
5157         "",
5158         "       srand(s_rand);  /* was: srandom(s_rand) */",
5159         "       nn[0] = ff[1]*ff[2]*ff[3]*ff[4];",
5160         "       nn[1] = ff[0]*ff[2]*ff[3]*ff[4];",
5161         "       nn[2] = ff[0]*ff[1]*ff[3]*ff[4];",
5162         "       nn[3] = ff[0]*ff[1]*ff[2]*ff[4];",
5163         "       nn[4] = ff[0]*ff[1]*ff[2]*ff[3];",
5164         "       for (cnt = 0; cnt < 5000; cnt++)",
5165         "       {       x = 2;",
5166         "               p = ((rand()<<13)^rand()) | 1; /* used random() before */",
5167         "               pp[0] = x;",
5168         "               for (i = 0; i < 32; i++)",
5169         "               {       pp[i+1] = mul(pp[i], pp[i], p);",
5170         "               }",
5171         "               if (pp[32] == x)",
5172         "               {       for (i = 0; i < 5; i++)",
5173         "                       {       y = ppow(nn[i], p);",
5174         "                               if (y == 1)",
5175         "                               {       break;",
5176         "                       }       }",
5177         "                       if (y != 1)",
5178         "                       {       HASH_CONST[0] = p;", /* 32 bit */
5179         "                               if (verbose)",
5180         "                               {       printf(\"polynomial: 0x%%.8x (%%d tries)\\n\",",
5181         "                                               p, cnt);",
5182         "                               }",
5183         "                               return;", /* success */
5184         "       }       }       }",
5185         "       fprintf(efd, \"pan: could not find a polynomial in %%d tries\\n\", cnt);",
5186         "       fprintf(efd, \"pan: try a different seed with -RSn\\n\");",
5187         "       exit(1);",
5188         "}",
5189         "",
5190         "int",
5191         "main(int argc, char *argv[])",
5192         "{      void to_compile(void);\n",
5193         "       efd = stderr;   /* default */",
5194         "#if defined(BFS_PAR) && defined(BFS_SEP_HASH)",
5195         "       uchar used_w = 0;",
5196         "#endif",
5197         "       if (G_long != sizeof(long)",
5198         "       ||  G_int  != sizeof(int))",
5199         "       {       printf(\"spin: error, the version of spin \");",
5200         "               printf(\"that generated this pan.c assumed a different \");",
5201         "               printf(\"wordsize (%%d iso %%d)\\n\", G_long, (int) sizeof(long));",
5202         "               exit(1);",
5203         "       }",
5204         "",
5205         "#if defined(T_RAND) && (T_RAND>0)",
5206         "       s_rand = T_RAND;", /* so that -RS can override */
5207         "#elif defined(P_RAND) && (P_RAND>0)",
5208         "       s_rand = P_RAND;",
5209         "#endif",
5210         "",
5211         "#ifdef PUTPID",
5212         "       {       char *ptr = strrchr(argv[0], '/');",
5213         "               if (ptr == NULL)",
5214         "               {       ptr = argv[0];",
5215         "               } else",
5216         "               {       ptr++;",
5217         "               }",
5218         "               progname = emalloc(strlen(ptr));",
5219         "               strcpy(progname, ptr);",
5220         "               /* printf(\"progname: %%s\\n\", progname); */",
5221         "       }",
5222         "#endif",
5223         "",
5224         "#ifdef BITSTATE",
5225         "       b_store = bstore_reg; /* default */",
5226         "#endif",
5227         "#if NCORE>1",
5228         "       {       int i, j;",
5229         "               strcpy(o_cmdline, \"\");",
5230         "               for (j = 1; j < argc; j++)",
5231         "               {       strcat(o_cmdline, argv[j]);",
5232         "                       strcat(o_cmdline, \" \");",
5233         "               }",
5234         "               /* printf(\"Command Line: %%s\\n\", o_cmdline); */",
5235         "               if (strlen(o_cmdline) >= sizeof(o_cmdline))",
5236         "               {       Uerror(\"option list too long\");",
5237         "       }       }",
5238         "#endif",
5239         "       while (argc > 1 && argv[1][0] == '-')",
5240         "       {       switch (argv[1][1]) {",
5241         "#ifndef SAFETY",
5242         "       #ifdef NP",
5243         "               case 'a': fprintf(efd, \"warning: -a is disabled by -DNP, ignored\");",
5244         "                         break;",
5245         "       #else",
5246         "               case 'a': a_cycles = 1; break;",
5247         "       #endif",
5248         "#else",
5249         "       #if defined(BFS_PAR) && defined(L_BOUND)",
5250         "               case 'a': if (isdigit(argv[1][2]))",
5251         "                         {     L_bound = atoi(&argv[1][2]);",
5252         "                               if (L_bound < 1 || L_bound > 255)",
5253         "                               {       printf(\"usage: -aN with 0<N<256\\n\");",
5254         "                                       exit(1);",
5255         "                         }     }",
5256         "                         break;",
5257         "       #endif",
5258         "#endif",
5259         "               case 'A': noasserts = 1; break;",
5260         "               case 'b': bounded = 1; break;",
5261         "#ifdef HAS_CODE",
5262         "       #if HAS_CODE>0",
5263         "               case 'C': coltrace = 1; goto samething;",
5264         "       #endif",
5265         "#endif",
5266         "               case 'c': upto = atoi(&argv[1][2]); break;",
5267         "               case 'D': dodot++; state_tables++; break;",
5268         "               case 'd': state_tables++; break;",
5269         "               case 'e': every_error = 1; upto = 0; Nr_Trails = 1; break;",
5270         "               case 'E': noends = 1; break;",
5271         "#ifdef SC",
5272         "               case 'F': if (strlen(argv[1]) > 2)",
5273         "                               stackfile = &argv[1][2];",
5274         "                         break;",
5275         "#endif",
5276         "#if !defined(SAFETY) && !defined(NOFAIR)",
5277         "               case 'f': fairness = 1; break;",
5278         "#endif",
5279         "#ifdef HAS_CODE",
5280         "       #if HAS_CODE>0",
5281         "               case 'g': gui = 1; goto samething;",
5282         "       #endif",
5283         "#endif",
5284         "               case 'h':",
5285         "                         if (strncmp(&argv[1][1], \"hash\", strlen(\"hash\")) == 0)",
5286         "                         {     do_hashgen = 1;",
5287         "                               break;",
5288         "                         }",
5289         "                         if (!argv[1][2] || !isdigit((int) argv[1][2]))",
5290         "                         {     usage(efd);     /* exits */",
5291         "                         }",
5292         "                         HASH_NR = atoi(&argv[1][2])%%(sizeof(HASH_CONST)/sizeof(uint));",
5293         "                         break;",
5294         "               case 'I': iterative = 2; every_error = 1; break;",
5295         "               case 'i':",
5296         "                         if (strncmp(&argv[1][1], \"i_reverse\", strlen(\"i_reverse\")) == 0)",
5297         "                         {     reversing |= 1;",
5298         "                         } else",
5299         "                         {     iterative   = 1;",
5300         "                               every_error = 1;",
5301         "                         }",
5302         "                         break;",
5303         "               case 'J': like_java = 1; break; /* Klaus Havelund */",
5304         "#ifdef BITSTATE",
5305         "               case 'k': hfns = atoi(&argv[1][2]); break;",
5306         "#endif",
5307         "#ifdef BCS",
5308         "               case 'L':",
5309         "                       sched_max = atoi(&argv[1][2]);",
5310         "                       if (sched_max > 255)    /* stored as one byte */",
5311         "                       {       fprintf(efd, \"warning: using max bound (255)\\n\");",
5312         "                               sched_max = 255;",
5313         "                       }",
5314         "       #ifndef NOREDUCE",
5315         "                       if (sched_max == 0)",
5316         "                       {       fprintf(efd, \"warning: with (default) bound -L0, \");",
5317         "                               fprintf(efd, \"using -DNOREDUCE performs better\\n\");",
5318         "                       }",
5319         "       #endif",
5320         "                       break;",
5321         "#endif",
5322         "#ifndef SAFETY",
5323                 "#ifdef NP",
5324         "               case 'l': a_cycles = 1; break;",
5325                 "#else",
5326         "               case 'l': fprintf(efd, \"error: -l not available (compile with -DNP)\");",
5327         "                         usage(efd); break;",
5328                 "#endif",
5329         "#endif",
5330         "#ifdef BITSTATE",
5331         "               case 'M': udmem = atoi(&argv[1][2]); break;",
5332         "               case 'G': udmem = atoi(&argv[1][2]); udmem *= 1024; break;",
5333         "#else",
5334         "               case 'M': case 'G':",
5335         "                         fprintf(stderr, \"-M and -G affect only -DBITSTATE\\n\");",
5336         "                         break;",
5337         "#endif",
5338         "               case 'm': maxdepth = atoi(&argv[1][2]); break;",
5339         "#ifndef NOCLAIM",
5340         "               case 'N':",
5341         "       #if NCLAIMS>1",
5342         "                         if (isdigit((int)argv[1][2]))",
5343         "                         {     whichclaim = atoi(&argv[1][2]);",
5344         "                         } else if (isalpha((int)argv[1][2]))",
5345         "                         {     claimname = &argv[1][2];",
5346         "                         } else if (argc > 2 && argv[2][0] != '-') /* check next arg */",
5347         "                         {     claimname = argv[2];",
5348         "                               argc--; argv++; /* skip next arg */",
5349         "                         }",
5350         "       #else",
5351         "               #if NCLAIMS==1",
5352         "                         fprintf(stderr, \"warning: only one claim defined, -N ignored\\n\");",
5353         "               #else",
5354         "                         fprintf(stderr, \"warning: no claims defined, -N ignored\\n\");",
5355         "               #endif",
5356         "                         if (!isdigit((int)argv[1][2]) && argc > 2 && argv[2][0] != '-')",
5357         "                         {     argc--; argv++;",
5358         "                         }",
5359         "       #endif",
5360         "#endif",
5361         "                         break;\n",
5362         "               case 'n': no_rck = 1; break;",
5363         "",
5364         "               case 'P':",
5365         "                         if (!readtrail",
5366         "                         &&  isdigit((int) argv[1][2]))", /* was argv[1][2] == '_' */
5367         "                         {     int x = atoi(&argv[1][2]);",
5368         "                               if (x != 0 && x != 1)",
5369         "                               {       fprintf(efd, \"pan: bad option -P[01], ignored\\n\");",
5370         "                               }",
5371         "                               if (x == 0)",
5372         "                               {       reversing &= ~1;",
5373         "                                       break;",
5374         "                               }",
5375         "                               if (x == 1)",
5376         "                               {       reversing |= 1;",
5377         "                                       break;",
5378         "                               }",
5379         "                               if (verbose)",
5380         "                               fprintf(efd, \"pan: reversed *active* process creation %%s\\n\",",
5381         "                                       reversing&1?\"on\":\"off\");",
5382         "                               break;",
5383         "                         } /* else */",
5384         "#ifdef HAS_CODE",
5385         "       #if HAS_CODE>0",
5386         "                         readtrail = 1; onlyproc = atoi(&argv[1][2]);",
5387         "                         if (argc > 2 && argv[2][0] != '-') /* check next arg */",
5388         "                         {     trailfilename = argv[2];",
5389         "                               argc--; argv++; /* skip next arg */",
5390         "                         }",
5391         "       #else",
5392         "                         fprintf(efd, \"pan: option -P not recognized, ignored\\n\");",
5393         "       #endif",
5394         "#else",
5395         "                         fprintf(efd, \"pan: option -P not recognized, ignored\\n\");",
5396         "#endif",
5397         "                         break;",
5398         "",
5399         "               case 'p':",
5400         "       #if !defined(BFS) && !defined(BFS_PAR)",
5401         "       #ifdef PERMUTED",
5402         "                         if (strncmp(&argv[1][1], \"p_normal\", strlen(\"p_normal\")) == 0)",
5403         "                         {     reversing &= ~2;",
5404         "                               break;",
5405         "                         }",
5406         "                         reversing |=2;",
5407         "                         if (strncmp(&argv[1][1], \"p_permute\", strlen(\"p_permute\")) == 0)",
5408         "                         {     p_reorder = set_permuted;",
5409         "                               break;",
5410         "                         }",
5411         "                         if (strncmp(&argv[1][1], \"p_rotate\", strlen(\"p_rotate\")) == 0)",
5412         "                         {     p_reorder = set_rotated;",
5413         "                               if (isdigit((int) argv[1][9]))",
5414         "                               {       p_rotate = atoi(&argv[1][9]);",
5415         "                               } else",
5416         "                               {       p_rotate = 1;",
5417         "                               }",
5418         "                               break;",
5419         "                         }",
5420         "                         if (strncmp(&argv[1][1], \"p_randrot\", strlen(\"p_randrot\")) == 0)",
5421         "                         {     p_reorder = set_randrot;",
5422         "                               break;",
5423         "                         }",
5424         "                         if (strncmp(&argv[1][1], \"p_reverse\", strlen(\"p_reverse\")) == 0)",
5425         "                         {     p_reorder = set_reversed;",
5426         "                               break;",
5427         "                         }",
5428         "       #else",
5429         "                         if (strncmp(&argv[1][1], \"p_permute\", strlen(\"p_permute\")) == 0",
5430         "                         ||  strncmp(&argv[1][1], \"p_rotate\",  strlen(\"p_rotate\")) == 0",
5431         "                         ||  strncmp(&argv[1][1], \"p_randrot\",  strlen(\"p_randrot\")) == 0",
5432         "                         ||  strncmp(&argv[1][1], \"p_reverse\", strlen(\"p_reverse\")) == 0)",
5433         "                         {     fprintf(efd, \"option %%s required compilation with -DPERMUTED\\n\",",
5434         "                                       argv[1]);",
5435         "                               exit(1);",
5436         "                         }",
5437         "       #endif",
5438         "       #endif",
5439         "#ifdef SVDUMP",
5440         "                         vprefix = atoi(&argv[1][2]);",
5441         "#else",
5442         "                         fprintf(efd, \"invalid option '%%s' -- ignored\\n\", argv[1]);",
5443         "#endif",
5444         "                         break;",
5445         "#if NCORE==1",
5446         "               case 'Q': quota = (double) 60.0 * (double) atoi(&argv[1][2]);",
5447         "       #ifndef FREQ",
5448         "                         freq /= 10.; /* for better resolution */",
5449         "       #endif",
5450         "                         break;",
5451         "#endif",
5452         "               case 'q': strict = 1; break;",
5453         "               case 'R':",
5454         "                       if (argv[1][2] == 'S') /* e.g., -RS76842 */",
5455         "                       {       s_rand = atoi(&argv[1][3]);", /* RS */
5456         "                               break;",
5457         "                       }",
5458         "#ifdef BITSTATE",
5459         "                       Nrun = atoi(&argv[1][2]);",
5460         "                       if (Nrun > 100)",
5461         "                       {       Nrun = 100;",
5462         "                       } else if (Nrun < 1)",
5463         "                       {       Nrun = 1;",
5464         "                       }",
5465         "#else",
5466         "                       usage(efd);",
5467         "                       break;",
5468         "#endif",
5469         "               case 'r':",
5470         "                         if (strncmp(&argv[1][1], \"rhash\", strlen(\"rhash\")) == 0)",
5471         "                         {     if (s_rand == 12345)    /* default seed */",
5472         "                               {",
5473         "#if defined(WIN32) || defined(WIN64)",
5474         "                                       s_rand = (uint) clock();",
5475         "#else",
5476         "                                       struct tms dummy_tm;",
5477         "                                       s_rand = (uint) times(&dummy_tm);",
5478         "#endif",
5479         "                               }",
5480         "                               srand(s_rand++);",
5481         "       #ifdef PERMUTED",
5482         "                               do_hashgen = 1;",       /* + randomize p_rotate, p_reverse, p_permute */
5483         "                               switch (rand()%%5) {",
5484         "                               case 0: p_reorder = set_permuted;",
5485         "                                       reversing |=2;",
5486         "                                       break;",
5487         "                               case 1: p_reorder = set_reversed;",
5488         "                                       reversing |=2;",
5489         "                                       break;",
5490         "                                       /* fully randomize p_rotate: */",
5491         "                               case 2: p_reorder = set_randrot;",
5492         "                                       reversing |=2;",
5493         "                                       break;",
5494         "                                       /* choose once, then keep p_rotate fixed: */",
5495         "                               case 3: p_reorder = set_rotated;",
5496         "                                       p_rotate = rand()%%3;",
5497         "                                       reversing |=2;",
5498         "                                       break;",
5499         "                               default: /* standard search */ break;",
5500         "                               }",
5501         "                               if (rand()%%2 == 0)",
5502         "                               {       t_reverse = 1;",
5503         "                               }",
5504         "                               break;",
5505         "       #else",
5506         "                               fprintf(efd, \"option -rhash requires compilation with -DPERMUTED\\n\");",
5507         "                               exit(1);",
5508         "       #endif",
5509         "                         }",
5510         "#if defined(HAS_CODE) && HAS_CODE>0",
5511         "samething:               readtrail = 1;",
5512         "                         if (isdigit((int)argv[1][2]))",
5513         "                               whichtrail = atoi(&argv[1][2]);",
5514         "                         else if (argc > 2 && argv[2][0] != '-') /* check next arg */",
5515         "                         {     trailfilename = argv[2];",
5516         "                               argc--; argv++; /* skip next arg */",
5517         "                         }",
5518         "                         break;",
5519         "               case 'S': silent = 1; goto samething;",
5520         "#else",
5521         "                         fprintf(efd, \"options -r is for models with embedded C code\\n\");",
5522         "                         break;",
5523         "#endif",
5524         "               case 'T':",
5525         "                         if (isdigit((int) argv[1][2]))", /* was argv[1][2] == '_' */
5526         "                         {     t_reverse = atoi(&argv[1][2]);",
5527         "                               if (verbose)",
5528         "                               printf(\"pan: reverse transition ordering %%s\\n\",",
5529         "                                       t_reverse?\"on\":\"off\");",
5530         "                               break;",
5531         "                         }",
5532         "                         TMODE = 0444;",
5533         "                         break;",
5534         "               case 't':",
5535         "                         if (strncmp(&argv[1][1], \"t_reverse\", strlen(\"t_reverse\")) == 0)",
5536         "                         {     t_reverse = 1;",
5537         "                               break;",
5538         "                         }", /* i.e., a trail prefix cannot be '_reverse' */
5539         "                         if (argv[1][2])",
5540         "                         {     tprefix = &argv[1][2];",
5541         "                         }",
5542         "                         break;",
5543         "               case 'u':",
5544         "       #ifdef BFS_PAR",
5545         "                         ncores = atoi(&argv[1][2]);",
5546         "       #endif",
5547         "                         break;",
5548         "               case 'V': start_timer(); printf(\"Generated by %%s\\n\", SpinVersion);",
5549         "                         to_compile(); pan_exit(2); break;",
5550         "               case 'v': verbose++; break;",
5551         "               case 'w': ssize = atoi(&argv[1][2]);",
5552         "       #if defined(BFS_PAR) && defined(BFS_SEP_HASH)",
5553         "                         used_w = 1;",
5554         "       #endif",
5555         "                         break;",
5556         "               case 'Y': signoff = 1; break;",
5557         "               case 'X': efd = stdout; break;",
5558         "               case 'x': exclusive = 1; break;",
5559         "       #if NCORE>1",
5560         "               /* -B ip is passthru to proxy of remote ip address: */",
5561         "               case 'B': argc--; argv++; break;",
5562         "               case 'Q': worker_pids[0] = atoi(&argv[1][2]); break;",
5563         "               /* -Un means that the nth worker should be instantiated as a proxy */",
5564         "               case 'U': proxy_pid = atoi(&argv[1][2]); break;",
5565         "               /* -W means this copy is started by a cluster-server as a remote */",
5566         "               /* this flag is passed to ./pan_proxy, which interprets it */",
5567         "               case 'W': remote_party++; break;",
5568         "               case 'Z': core_id = atoi(&argv[1][2]);",
5569         "                         if (verbose)",
5570         "                         { printf(\"cpu%%d: pid %%d parent %%d\\n\",",
5571         "                               core_id, getpid(), worker_pids[0]);",
5572         "                         }",
5573         "                         break;",
5574         "               case 'z': z_handoff = atoi(&argv[1][2]); break;",
5575         "       #else",
5576         "               case 'z': break; /* ignored for single-core */",
5577         "       #endif",
5578         "               default : fprintf(efd, \"saw option -%%c\\n\",",
5579         "                               argv[1][1]); usage(efd); break;",
5580         "               }",
5581         "               argc--; argv++;",
5582         "       }",
5583         "#if defined(BFS_PAR) && defined(BFS_SEP_HASH)",
5584         "       if (used_w == 0)",
5585         "       {       if (ncores == 0) /* all cores used, by default */",
5586         "               {       ssize -= blog2(BFS_MAXPROCS - 1);",
5587         "               } else",
5588         "               {       ssize -= blog2(ncores);",
5589         "       }       }",
5590         "#endif",
5591         "       if (do_hashgen)",
5592         "       {       hashgen();", /* placed here so that -RSn can appear after -hash */
5593         "       }",
5594         "#ifndef SAFETY",
5595         "       if (fairness && !a_cycles)",
5596         "       {       fprintf(efd, \"error: -f requires the use of -a or -l\\n\");", 
5597         "               usage(efd);",
5598         "       }",
5599         "       #if ACCEPT_LAB==0",
5600         "       if (a_cycles)",
5601         "       {       fprintf(efd, \"warning: no accept labels are defined, \");",
5602         "               fprintf(efd, \"so option -a has no effect (ignored)\\n\");",
5603         "               a_cycles = 0;",
5604         "       }",
5605         "       #endif",
5606         "#endif",
5607         "",
5608         "#ifdef BFS_PAR",
5609         "       uerror = bfs_uerror;",
5610         "       Uerror = bfs_Uerror;",
5611         "#else",
5612         "       uerror = dfs_uerror;",
5613         "       Uerror = dfs_Uerror;",
5614         "#endif",
5615         "       if (ssize <= 32)        /* 6.2.0 */",
5616         "       {       hasher = d_sfh;",
5617         "#if !defined(BITSTATE) && defined(USE_TDH)",
5618         "               o_hash = o_hash32;",
5619         "#endif",
5620         "       } else",
5621         "       {       hasher = d_hash;",
5622         "#if !defined(BITSTATE) && defined(USE_TDH)",
5623         "               o_hash = o_hash64;",
5624         "#endif",
5625         "       }",
5626         "       if (iterative && TMODE != 0666)",
5627         "       {       TMODE = 0666;",
5628         "               fprintf(efd, \"warning: -T ignored when -i or -I is used\\n\");",
5629         "       }",
5630         "#if defined(WIN32) || defined(WIN64)",
5631         "       #ifndef _S_IWRITE",
5632         "               #define S_IWRITE 0000200  /* write permission, owner */",
5633         "       #endif",
5634         "       #ifndef _S_IREAD",
5635         "               #define S_IREAD  0000400  /* read permission, owner */",
5636         "       #endif",
5637         "       if (TMODE == 0666)",
5638         "               TMODE = S_IWRITE | S_IREAD;",
5639         "       else",
5640         "               TMODE = S_IREAD;",
5641         "#endif",
5642         "#if NCORE>1",
5643         "       store_proxy_pid = proxy_pid; /* for checks in mem_file() and someone_crashed() */",
5644         "       if (core_id != 0) { proxy_pid = 0; }",
5645         "       #ifndef SEP_STATE",
5646         "       if (core_id == 0 && a_cycles)",
5647         "       {       fprintf(efd, \"hint: this search may be more efficient \");",
5648         "               fprintf(efd, \"if pan.c is compiled -DSEP_STATE\\n\");",
5649         "       }",
5650         "       #endif",
5651         "       if (z_handoff < 0)",
5652         "       {       z_handoff =  20; /* conservative default - for non-liveness checks */",
5653         "       }",
5654         "#if defined(NGQ) || defined(LWQ_FIXED)",
5655         "       LWQ_SIZE = (double) (128.*1048576.);",
5656         "#else",
5657         "       LWQ_SIZE = (double) ( z_handoff + 2.) * (double) sizeof(SM_frame);",
5658                 /* the added margin of +2 is not really necessary */
5659         "#endif",
5660         "       #if NCORE>2",
5661         "       if (a_cycles)",
5662         "       {       fprintf(efd, \"warning: the intended nr of cores to be used in liveness mode is 2\\n\");",
5663         "               #ifndef SEP_STATE",
5664         "               fprintf(efd, \"warning: without -DSEP_STATE there is no guarantee that all liveness violations are found\\n\");",
5665         "               #endif",
5666         "       }",     /* it still works though, the later cores get states from the global q */
5667         "       #endif",
5668         "       #ifdef HAS_HIDDEN",
5669         "       #error cannot use hidden variables when compiling multi-core",
5670         "       #endif",
5671         "#endif",
5672         "#if defined(T_RAND) && defined(ELSE_IN_GUARD)",
5673         "       #error cannot hide 'else' as guard in d_step, when using -DT_RAND",
5674         "#endif",
5675         "#ifdef BITSTATE",
5676         "       if (hfns <= 0)",
5677         "       {       hfns = 1;",
5678         "               fprintf(efd, \"warning: using -k%%d as minimal usable value\\n\", hfns);",
5679         "       }",
5680         "#endif",
5681         "       omaxdepth = maxdepth;",
5682         "#ifdef BITSTATE",
5683         "       if (WS == 4 && ssize > 34)",    /* 32-bit word size */
5684         "       {       ssize = 34;",
5685         "               fprintf(efd, \"warning: using -w%%d as max usable value\\n\", ssize);",
5686         "/*",
5687         " *     -w35 would not work: 35-3 = 32 but 1^31 is the largest",
5688         " *     power of 2 that can be represented in an ulong",
5689         " */",
5690         "       }",
5691         "#else",
5692         "       if (WS == 4 && ssize > 27)",
5693         "       {       ssize = 27;",
5694         "               fprintf(efd, \"warning: using -w%%d as max usable value\\n\", ssize);",
5695         "/*",
5696         " *     for emalloc, the lookup table size multiplies by 4 for the pointers",
5697         " *     the largest power of 2 that can be represented in a ulong is 1^31",
5698         " *     hence the largest number of lookup table slots is 31-4 = 27",
5699         " */",
5700         "       }",
5701
5702         "#endif",
5703         "#ifdef SC",
5704         "       hiwater = HHH = maxdepth-10;",
5705         "       DDD = HHH/2;",
5706         "       if (!stackfile)",
5707         "       {       stackfile = (char *) emalloc(strlen(PanSource)+4+1);",
5708         "               sprintf(stackfile, \"%%s._s_\", PanSource);",
5709         "       }",
5710         "       if (iterative)",
5711         "       {       fprintf(efd, \"error: cannot use -i or -I with -DSC\\n\");",
5712         "               pan_exit(1);",
5713         "       }",
5714         "#endif",
5715
5716         "#if (defined(R_XPT) || defined(W_XPT)) && !defined(MA)",
5717         "       #warning -DR_XPT and -DW_XPT assume -DMA (ignored)",
5718         "#endif",
5719
5720         "       if (iterative && a_cycles)",
5721         "       fprintf(efd, \"warning: -i or -I work for safety properties only\\n\");",
5722
5723         "#ifdef BFS",
5724         "       #ifdef SC",
5725         "               #error -DBFS not compatible with -DSC",
5726         "       #endif",
5727         "       #ifdef HAS_LAST",
5728         "               #error -DBFS not compatible with _last",
5729         "       #endif",
5730         "       #ifdef HAS_STACK",
5731         "               #error cannot use c_track UnMatched with BFS",
5732         "       #endif",
5733         "       #ifdef BCS",
5734         "               #error -DBFS not compatible with -DBCS",
5735         "       #endif",
5736         "       #ifdef REACH",
5737         "               #warning -DREACH is redundant when -DBFS is used",
5738         "       #endif",
5739         "#endif",
5740
5741         "#ifdef TRIX",
5742         "       #ifdef BITSTATE",
5743         "               #error cannot combine -DTRIX and -DBITSTATE",
5744         "       #endif",
5745         "       #ifdef COLLAPSE",
5746         "               #error cannot combine -DTRIX and -DCOLLAPSE",
5747         "       #endif",
5748         "       #ifdef MA",
5749         "               #error cannot combine -DTRIX and -DMA",
5750         "       #endif",
5751         "       #if defined(BFS_PAR) && defined(BFS_SEP_HEAP)",
5752         "               #error cannot combined -DBFS_SEP_HEAP with -DTRIX",
5753         "       #endif",
5754         "#endif",
5755
5756         "#ifdef BFS_PAR",
5757         "       #ifdef NP",
5758         "       #error cannot combine -DBFS_PAR and -DNP",
5759         "       #undef NP",
5760         "       #endif",
5761         "#endif",
5762
5763         "#ifdef NOCLAIM",
5764         "       #ifdef NP",
5765         "       #warning using -DNP overrides -DNOCLAIM",
5766         "       #undef NOCLAIM",
5767         "       #endif",
5768         "#endif",
5769
5770         "#ifdef BCS",
5771         "       #ifdef P_RAND",
5772         "               #error cannot combine -DBCS and -DP_RAND",
5773         "       #endif",
5774         "       #ifdef BFS",
5775         "               #error cannot combine -DBCS and -DBFS",
5776         "       #endif",
5777         "#endif",
5778
5779         "#if defined(MERGED) && defined(PEG)",
5780         "       #error to use -DPEG use: spin -o3 -a",
5781         "#endif",
5782         "#if defined(HC) && !defined(BFS_PAR)",
5783         "       #ifdef NOCOMP",
5784         "               #error cannot combine -DHC and -DNOCOMP",
5785         "       #endif",
5786         "       #ifdef BITSTATE",
5787         "               #error cannot combine -DHC and -DBITSTATE",
5788         "       #endif",
5789         "#endif",
5790         "#if defined(SAFETY) && defined(NP)",
5791         "       #error cannot combine -DNP and -DBFS or -DSAFETY",
5792         "#endif",
5793         "#ifdef MA",
5794         "       #ifdef BITSTATE",
5795         "               #error cannot combine -DMA and -DBITSTATE",
5796         "       #endif",
5797         "       #if MA <= 0",
5798         "               #error usage: -DMA=N with N > 0 and N < VECTORSZ",
5799         "       #endif",
5800         "#endif",
5801         "#ifdef COLLAPSE",
5802         "       #ifdef BITSTATE",
5803         "               #error cannot combine -DBITSTATE and -DCOLLAPSE",
5804         "       #endif",
5805         "       #ifdef NOCOMP",
5806         "               #error cannot combine -DCOLLAPSE and -DNOCOMP",
5807         "       #endif",
5808         "#endif",
5809         "       if (maxdepth <= 0 || ssize <= 1) usage(efd);",
5810         "#if SYNC>0 && !defined(NOREDUCE)",
5811         "       if (a_cycles && fairness)",
5812         "       { fprintf(efd, \"error: p.o. reduction not compatible with \");",
5813         "         fprintf(efd, \"fairness (-f) in models\\n\");",
5814         "         fprintf(efd, \"       with rendezvous operations: \");",
5815         "         fprintf(efd, \"recompile with -DNOREDUCE\\n\");",
5816         "         pan_exit(1);",
5817         "       }",
5818         "#endif",
5819         "#if defined(REM_VARS) && !defined(NOREDUCE)",
5820         "       #warning p.o. reduction not compatible with remote varrefs (use -DNOREDUCE)",
5821         "#endif",
5822         "#if defined(NOCOMP) && !defined(BITSTATE)",
5823         "       if (a_cycles)",
5824         "       { fprintf(efd, \"error: use of -DNOCOMP voids -l and -a\\n\");",
5825         "         pan_exit(1);",
5826         "       }",
5827         "#endif",
5828         "#ifdef MEMLIM",
5829         "       memlim = ((double) MEMLIM) * (double) (1<<20);  /* size in Mbyte */",
5830         "#endif",
5831         "#if SYNC>0",
5832         "       #ifdef HAS_PRIORITY",
5833         "               #error use of priorities cannot be combined with rendezvous",
5834         "       #elif HAS_ENABLED",
5835         "               #error use of enabled() cannot be combined with rendezvous",
5836         "       #endif",
5837         "#endif",
5838         "#ifndef NOREDUCE",
5839         "       #ifdef HAS_PRIORITY",
5840         "               #warning use of priorities requires -DNOREDUCE",
5841         "       #elif HAS_ENABLED",
5842         "               #error use of enabled() requires -DNOREDUCE",
5843         "       #endif",
5844         "       #ifdef HAS_PCVALUE",
5845         "               #error use of pcvalue() requires -DNOREDUCE",
5846         "       #endif",
5847         "       #ifdef HAS_BADELSE",
5848         "               #error use of 'else' combined with i/o stmnts requires -DNOREDUCE",
5849         "       #endif",
5850         "       #if defined(HAS_LAST) && !defined(BCS)",
5851         "               #error use of _last requires -DNOREDUCE",
5852         "       #endif",
5853         "#endif",
5854
5855         "#if SYNC>0 && !defined(NOREDUCE)",
5856         "       #ifdef HAS_UNLESS",
5857         "       fprintf(efd, \"warning: use of a rendezvous stmnts in the escape\\n\");",
5858         "       fprintf(efd, \"\tof an unless clause, if present, could make p.o. reduction\\n\");",
5859         "       fprintf(efd, \"\tinvalid (use -DNOREDUCE to avoid this)\\n\");",
5860         "               #ifdef BFS",
5861         "               fprintf(efd, \"\t(this type of rv is also not compatible with -DBFS)\\n\");",
5862         "               #endif",
5863         "       #endif",
5864         "#endif",
5865         "#if SYNC>0 && defined(BFS)",
5866         "       if (!noends)",
5867         "       fprintf(efd, \"warning: use of rendezvous with BFS does not preserve all invalid endstates\\n\");",
5868         "#endif",
5869         "#if !defined(REACH) && !defined(BITSTATE)",
5870         "       if (iterative != 0 && a_cycles == 0)",
5871         "       {       fprintf(efd, \"warning: -i and -I need -DREACH to work accurately\\n\");",
5872         "       }",
5873         "#endif",
5874         "#if defined(BITSTATE) && defined(REACH)",
5875         "       #warning -DREACH is voided by -DBITSTATE",
5876         "#endif",
5877         "#if defined(MA) && defined(REACH)",
5878         "       #warning -DREACH is voided by -DMA",
5879         "#endif",
5880         "#if defined(FULLSTACK) && defined(CNTRSTACK)",
5881         "       #error cannot combine -DFULLSTACK and -DCNTRSTACK",
5882         "#endif",
5883         "#if defined(VERI)",
5884         "       #if ACCEPT_LAB>0",
5885         "               #ifndef BFS",
5886         "                       if (!a_cycles",
5887         "                       #ifdef HAS_CODE",
5888         "                       && !readtrail",
5889         "                       #endif",
5890         "                       #if NCORE>1",
5891         "                       && core_id == 0",
5892         "                       #endif",
5893         "                       && !state_tables)",
5894         "                       { fprintf(efd, \"warning: never claim + accept labels \");",
5895         "                         fprintf(efd, \"requires -a flag to fully verify\\n\");",
5896         "                       }",
5897         "               #else",
5898         "                       if (verbose && !state_tables",
5899         "                       #ifdef HAS_CODE",
5900         "                       && !readtrail",
5901         "                       #endif",
5902         "                       )",
5903         "                       { fprintf(efd, \"warning: verification in BFS mode \");",
5904         "                         fprintf(efd, \"is restricted to safety properties\\n\");",
5905         "                       }",
5906         "               #endif",
5907         "       #endif",
5908         "#endif",
5909         "#ifndef SAFETY",
5910         "  #if 0",
5911         "       if (!a_cycles",
5912         "       #ifdef HAS_CODE",
5913         "       && !readtrail",
5914         "       #endif",
5915         "       #if NCORE>1",
5916         "       && core_id == 0",
5917         "       #endif",
5918         "       && !state_tables)",
5919         "       { fprintf(efd, \"hint: this search is more efficient \");",
5920         "         fprintf(efd, \"if pan.c is compiled -DSAFETY\\n\");",
5921         "       }",
5922         "  #endif",
5923         "       #ifndef NOCOMP",
5924         "       if (!a_cycles)",
5925         "       {       S_A = 0;",
5926         "       } else",
5927         "       {       if (!fairness)",
5928         "               {       S_A = 1; /* _a_t */",
5929         "               #ifndef NOFAIR",
5930         "               } else /* _a_t and _cnt[NFAIR] */",
5931         "               {  S_A = (&(now._cnt[0]) - (uchar *) &now) + NFAIR - 2;",
5932         "               /* -2 because first two uchars in now are masked */",
5933         "               #endif",
5934         "       }       }",
5935         "       #endif",
5936         "#endif",
5937         "       signal(SIGINT, stopped);",
5938         "       set_masks();",
5939         "#if defined(BFS) || defined(BFS_PAR)",
5940         "       trail = (Trail *) emalloc(6*sizeof(Trail));",
5941         "       trail += 3;",
5942         "#else",
5943         "       trail = (Trail *) emalloc((maxdepth+3)*sizeof(Trail));",
5944         "       trail++;        /* protect trpt-1 refs at depth 0 */",
5945         "#endif",
5946         "       trpt = &trail[0]; /* precaution -- in case uerror is called early */",
5947         "#ifdef BFS",
5948         "       ntrpt = trpt;",
5949         "#endif",
5950         "#ifdef SVDUMP",
5951         "       if (vprefix > 0)",
5952         "       {       char nm[64];",
5953         "               sprintf(nm, \"%%s.svd\", PanSource);",
5954         "               if ((svfd = creat(nm, TMODE)) < 0)",
5955         "               {       fprintf(efd, \"couldn't create %%s\\n\", nm);",
5956         "                       vprefix = 0;",
5957         "       }       }",
5958         "#endif",
5959         "#ifdef RANDSTOR",
5960         "       srand(s_rand+HASH_NR);", /* main - RANDSTOR */
5961         "#endif",
5962         "#if SYNC>0 && ASYNC==0",
5963         "       set_recvs();",
5964         "#endif",
5965         "       run();",
5966         "       done = 1;",
5967         "       wrapup();",
5968         "       return 0;",
5969         "}",    /* end of main() */
5970         "",
5971         "void",
5972         "usage(FILE *fd)",
5973         "{",
5974         "       fprintf(fd, \"%%s\\n\", SpinVersion);",
5975         "       fprintf(fd, \"Valid Options are:\\n\");",
5976         "#ifndef SAFETY",
5977                 "#ifdef NP",
5978         "       fprintf(fd, \"\t-a  -> is disabled by -DNP \");",
5979         "       fprintf(fd, \"(-DNP compiles for -l only)\\n\");",
5980                 "#else",
5981         "       fprintf(fd, \"\t-a  find acceptance cycles\\n\");",
5982                 "#endif",
5983         "#else",
5984         "       fprintf(fd, \"\t-a,-l,-f  -> are disabled by -DSAFETY\\n\");",
5985         "#endif",
5986         "       fprintf(fd, \"\t-A  ignore assert() violations\\n\");",
5987         "       fprintf(fd, \"\t-b  consider it an error to exceed the depth-limit\\n\");",
5988         "       fprintf(fd, \"\t-cN stop at Nth error \");",
5989         "       fprintf(fd, \"(defaults to -c1)\\n\");",
5990         "       fprintf(fd, \"\t-D  print state tables in dot-format and stop\\n\");",
5991         "       fprintf(fd, \"\t-d  print state tables and stop\\n\");",
5992         "       fprintf(fd, \"\t-e  create trails for all errors\\n\");",
5993         "       fprintf(fd, \"\t-E  ignore invalid end states\\n\");",
5994         "#ifdef SC",
5995         "       fprintf(fd, \"\t-Ffile  use 'file' to store disk-stack\\n\");",
5996         "#endif",
5997         "#ifndef NOFAIR",
5998         "       fprintf(fd, \"\t-f  add weak fairness (to -a or -l)\\n\");",
5999         "#endif",
6000         "       fprintf(fd, \"\t-hN use different hash-seed N:0..499 (defaults to -h0)\\n\");",
6001         "       fprintf(fd, \"\t-hash generate a random hash-polynomial for -h0 (see also -rhash)\\n\");",
6002         "       fprintf(fd, \"\t      using a seed set with -RSn (default %%u)\\n\", s_rand);",
6003         "       fprintf(fd, \"\t-i  search for shortest path to error\\n\");",
6004         "       fprintf(fd, \"\t-I  like -i, but approximate and faster\\n\");",
6005         "       fprintf(fd, \"\t-J  reverse eval order of nested unlesses\\n\");",
6006         "#ifdef BITSTATE",
6007         "       fprintf(fd, \"\t-kN set N bits per state (defaults to 3)\\n\");",
6008         "#endif",
6009         "#ifdef BCS",
6010         "       fprintf(fd, \"\t-LN set scheduling restriction to N (default 0)\\n\");",
6011         "#endif",
6012         "#ifndef SAFETY",
6013                 "#ifdef NP",
6014         "       fprintf(fd, \"\t-l  find non-progress cycles\\n\");",
6015                 "#else",
6016         "       fprintf(fd, \"\t-l  find non-progress cycles -> \");",
6017         "       fprintf(fd, \"disabled, requires \");",
6018         "       fprintf(fd, \"compilation with -DNP\\n\");",
6019                 "#endif",
6020         "#endif",
6021         "#ifdef BITSTATE",
6022         "       fprintf(fd, \"\t-MN use N Megabytes for bitstate hash array\\n\");",
6023         "       fprintf(fd, \"\t-GN use N Gigabytes for bitstate hash array\\n\");",
6024         "#endif",
6025         "       fprintf(fd, \"\t-mN max depth N steps (default=10k)\\n\");",
6026         "#if NCLAIMS>1",
6027         "       fprintf(fd, \"\t-N cn -- use the claim named cn\\n\");",
6028         "       fprintf(fd, \"\t-Nn   -- use claim number n\\n\");",
6029         "#endif",
6030         "       fprintf(fd, \"\t-n  no listing of unreached states\\n\");",
6031         "#ifdef PERMUTED",
6032         "       fprintf(fd, \"\t-p_permute randomize order in which processes are scheduled (see also -rhash)\\n\");",
6033         "       fprintf(fd, \"\t-p_reverse reverse order in which processes are scheduled (see also -rhash)\\n\");",
6034         "       fprintf(fd, \"\t-p_rotateN rotate by N the process scheduling order (see also -rhash)\\n\");",
6035         "#endif",
6036         "#ifdef SVDUMP",
6037         "       fprintf(fd, \"\t-pN create svfile (save N bytes per state)\\n\");",
6038         "#endif",
6039         "       fprintf(fd, \"\t-QN set time-limit on execution of N minutes\\n\");",
6040         "       fprintf(fd, \"\t-q  require empty chans in valid end states\\n\");",
6041         "#ifdef HAS_CODE",
6042         "       fprintf(fd, \"\t-r  read and execute trail - can add -v,-n,-PN,-g,-C\\n\");",
6043         "       fprintf(fd, \"\t-r trailfilename  read and execute trail in file\\n\");",
6044         "       fprintf(fd, \"\t-rN read and execute N-th error trail\\n\");",
6045         "       fprintf(fd, \"\t-C  read and execute trail - columnated output (can add -v,-n)\\n\");",
6046         "       fprintf(fd, \"\t-r -PN read and execute trail - restrict trail output to proc N\\n\");",
6047         "       fprintf(fd, \"\t-g  read and execute trail + msc gui support\\n\");",
6048         "       fprintf(fd, \"\t-S  silent replay: only user defined printfs show\\n\");",
6049         "#endif",
6050         "       fprintf(fd, \"\t-RSn use randomization seed n\\n\");",
6051         "       fprintf(fd, \"\t-rhash use random hash-polynomial and randomly choose -p_rotateN, -p_permute, or p_reverse\\n\");",
6052         "#ifdef BITSTATE",
6053         "       fprintf(fd, \"\t-Rn run n times n: [1..100] using n \");",
6054         "       fprintf(fd, \" different hash functions\\n\");",
6055         "#endif",
6056         "       fprintf(fd, \"\t-T  create trail files in read-only mode\\n\");",
6057         "       fprintf(fd, \"\t-t_reverse  reverse order in which transitions are explored\\n\");",
6058         "       fprintf(fd, \"\t-tsuf replace .trail with .suf on trailfiles\\n\");",
6059         "       fprintf(fd, \"\t-V  print SPIN version number\\n\");",
6060         "       fprintf(fd, \"\t-v  verbose -- filenames in unreached state listing\\n\");",
6061         "       fprintf(fd, \"\t-wN hashtable of 2^N entries \");",
6062         "       fprintf(fd, \"(defaults to -w%%d)\\n\", ssize);",
6063         "       fprintf(fd, \"\t-x  do not overwrite an existing trail file\\n\");",
6064         "#if NCORE>1",
6065         "       fprintf(fd, \"\t-zN handoff states below depth N to 2nd cpu (multi_core)\\n\");",
6066         "#endif",
6067         "#ifdef HAS_CODE",
6068         "       fprintf(fd, \"\\n\toptions -r, -C, -PN, -g, and -S can optionally be followed by\\n\");",
6069         "       fprintf(fd, \"\ta filename argument, as in \'-r filename\', naming the trailfile\\n\");",
6070         "#endif",
6071         "#if NCORE>1",
6072         "       multi_usage(fd);",
6073         "#endif",
6074         "       exit(1);",
6075         "}",
6076         "",
6077         "char *",
6078         "Malloc(ulong n)",
6079         "{      char *tmp;",
6080         "#ifdef MEMLIM",
6081         "       if (memcnt + (double) n > memlim)",
6082         "       {       printf(\"pan: reached -DMEMLIM bound\\n\");",
6083         "               goto err;",
6084         "       }",
6085         "#endif",
6086         "       tmp = (char *) malloc(n);",
6087         "       if (!tmp)",
6088         "       {",
6089         "#ifdef BFS_PAR",
6090         "               Uerror(\"out of non-shared memory\");",
6091         "#endif",
6092         "               printf(\"pan: out of memory\\n\");",
6093         "#ifdef MEMLIM",
6094         "err:",
6095         "               printf(\"\t%%g bytes used\\n\", memcnt);",
6096         "               printf(\"\t%%g bytes more needed\\n\", (double) n);",
6097         "               printf(\"\t%%g bytes limit\\n\", memlim);",
6098         "#endif",
6099         "#ifdef COLLAPSE",
6100         "               printf(\"hint: to reduce memory, recompile with\\n\");",
6101                 "#ifndef MA",
6102         "               printf(\"  -DMA=%%d   # better/slower compression, or\\n\", hmax);",
6103                 "#endif",
6104         "               printf(\"  -DBITSTATE # supertrace, approximation\\n\");",
6105         "#else",
6106         "#ifndef BITSTATE",
6107         "               printf(\"hint: to reduce memory, recompile with\\n\");",
6108                 "#ifndef HC",
6109         "               printf(\"  -DCOLLAPSE # good, fast compression, or\\n\");",
6110                         "#ifndef MA",
6111         "               printf(\"  -DMA=%%d   # better/slower compression, or\\n\", hmax);",
6112                         "#endif",
6113         "               printf(\"  -DHC # hash-compaction, approximation\\n\");",
6114                 "#endif",
6115         "               printf(\"  -DBITSTATE # supertrace, approximation\\n\");",
6116         "#endif",
6117         "#endif",
6118         "#if NCORE>1",
6119         "       #ifdef FULL_TRAIL",
6120         "               printf(\"  omit -DFULL_TRAIL or use pan -c0 to reduce memory\\n\");",
6121         "       #endif",
6122         "       #ifdef SEP_STATE",
6123         "               printf(\"hint: to reduce memory, recompile without\\n\");",
6124         "               printf(\"  -DSEP_STATE # may be faster, but uses more memory\\n\");",
6125         "       #endif",
6126         "#endif",
6127         "               wrapup();",
6128         "       }",
6129         "       memcnt += (double) n;",
6130         "       return tmp;",
6131         "}",
6132         "",
6133         "#define CHUNK  (100*VECTORSZ)",
6134         "",
6135         "char *",
6136         "emalloc(ulong n) /* never released or reallocated */",
6137         "{      char *tmp;",
6138         "       if (n == 0)",
6139         "               return (char *) NULL;",
6140         "       if (n&(sizeof(void *)-1)) /* for proper alignment */",
6141         "               n += sizeof(void *)-(n&(sizeof(void *)-1));",
6142         "       if ((ulong) left < n)", /* was: (left < (long)n) */
6143         "       {       grow = (n < CHUNK) ? CHUNK : n;",
6144 #if 1
6145         "               have = Malloc(grow);",
6146 #else
6147         "               /* gcc's sbrk can give non-aligned result */",
6148         "               grow += sizeof(void *); /* allow realignment */",
6149         "               have = Malloc(grow);",
6150         "               if (((unsigned) have)&(sizeof(void *)-1))",
6151         "               {       have += (long) (sizeof(void *) ",
6152         "                               - (((unsigned) have)&(sizeof(void *)-1)));",
6153         "                       grow -= sizeof(void *);",
6154         "               }",
6155 #endif
6156         "               fragment += (double) left;",
6157         "               left = grow;",
6158         "       }",
6159         "       tmp = have;",
6160         "       have += (long) n;",
6161         "       left -= (long) n;",
6162         "       memset(tmp, 0, n);",
6163         "       return tmp;",
6164         "}",
6165
6166         "void",
6167         "dfs_Uerror(char *str)",
6168         "{      /* always fatal */",
6169         "       uerror(str);",
6170         "#if NCORE>1",
6171         "       sudden_stop(\"Uerror\");",
6172         "#endif",
6173         "#ifdef BFS_PAR",
6174         "       bfs_shutdown(\"Uerror\");",
6175         "#endif",
6176         "       wrapup();",
6177         "}\n",
6178         "#if defined(MA) && !defined(SAFETY)",
6179         "int",
6180         "Unwind(void)",
6181         "{      Trans *t; uchar ot, _m; int tt; short II;",
6182         "#ifdef VERBOSE",
6183         "       int i;",
6184         "#endif",
6185         "       uchar oat = now._a_t;",
6186         "       now._a_t &= ~(1|16|32);",
6187         "       memcpy((char *) &comp_now, (char *) &now, vsize);",
6188         "       now._a_t = oat;",
6189         "Up:",
6190         "#ifdef SC",
6191         "       trpt = getframe(depth);",
6192         "#endif",
6193         "#ifdef VERBOSE",
6194         "       printf(\"%%ld    State: \", depth);",
6195         "#if !defined(NOCOMP) && !defined(HC)",
6196         "       for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
6197         "               ((char *)&now)[i], Mask[i]?\"*\":\"\");",
6198         "#else",
6199         "       for (i = 0; i < vsize; i++)",
6200         "               printf(\"%%d,\", ((char *)&now)[i]);",
6201         "#endif",
6202         "       printf(\"\\n\");",
6203         "#endif",
6204         "#ifndef NOFAIR",
6205         "       if (trpt->o_pm&128)     /* fairness alg */",
6206         "       {       now._cnt[now._a_t&1] = trpt->bup.oval;",
6207         "               depth--;",
6208         "#ifdef SC",
6209         "               trpt = getframe(depth);",
6210         "#else",
6211         "               trpt--;",
6212         "#endif",
6213         "               goto Q999;",
6214         "       }",
6215         "#endif",
6216         "#ifdef HAS_LAST",
6217         "#ifdef VERI",
6218         "       { long d; Trail *trl;",
6219         "         now._last = 0;",
6220         "         for (d = 1; d < depth; d++)",
6221         "         {     trl = getframe(depth-d); /* was trl = (trpt-d); */",
6222         "               if (trl->pr != 0)",
6223         "               { now._last = trl->pr - BASE;",
6224         "                 break;",
6225         "       } }     }",
6226         "#else",
6227         "       now._last = (depth<1)?0:(trpt-1)->pr;",
6228         "#endif",
6229         "#endif",
6230         "#ifdef EVENT_TRACE",
6231         "       now._event = trpt->o_event;",
6232         "#endif",
6233         "       if ((now._a_t&1) && depth <= A_depth)",
6234         "       {       now._a_t &= ~(1|16|32);",
6235         "               if (fairness) now._a_t |= 2;    /* ? */",
6236         "               A_depth = 0;",
6237         "               goto CameFromHere;      /* checkcycles() */",
6238         "       }",
6239         "       t  = trpt->o_t;",
6240         "       ot = trpt->o_ot; II = trpt->pr;",
6241         "       tt = trpt->o_tt; this = pptr(II);",
6242         "       _m = do_reverse(t, II, trpt->o_m);",
6243         "#ifdef VERBOSE",
6244         "       printf(\"%%3ld: proc %%d \", depth, II);",
6245         "       printf(\"reverses %%d, %%d to %%d,\",",
6246         "               t->forw, tt, t->st);",
6247         "       printf(\" %%s [abit=%%d,adepth=%%ld,\", ",
6248         "               t->tp, now._a_t, A_depth);",
6249         "       printf(\"tau=%%d,%%d] <unwind>\\n\", ",
6250         "               trpt->tau, (trpt-1)->tau);",
6251         "#endif",
6252         "       depth--;",
6253         "#ifdef SC",
6254         "       trpt = getframe(depth);",
6255         "#else",
6256         "       trpt--;",
6257         "#endif",
6258         "       /* reached[ot][t->st] = 1;      3.4.13 */",
6259         "       ((P0 *)this)->_p = tt;",
6260         "#ifndef NOFAIR",
6261         "       if ((trpt->o_pm&32))",
6262         "       {",
6263                 "#ifdef VERI",
6264         "               if (now._cnt[now._a_t&1] == 0)",
6265         "                       now._cnt[now._a_t&1] = 1;",
6266                 "#endif",
6267         "               now._cnt[now._a_t&1] += 1;",
6268         "       }",
6269         "Q999:",
6270         "       if (trpt->o_pm&8)",
6271         "       {       now._a_t &= ~2;",
6272         "               now._cnt[now._a_t&1] = 0;",
6273         "       }",
6274         "       if (trpt->o_pm&16)",
6275         "               now._a_t |= 2;",
6276         "#endif",
6277         "CameFromHere:",
6278         "       if (memcmp((char *) &now, (char *) &comp_now, vsize) == 0)",
6279         "               return depth;",
6280         "       if (depth > 0) goto Up;",
6281         "       return 0;",
6282         "}",
6283         "#endif",
6284         "static char unwinding;",
6285         "void",
6286         "dfs_uerror(char *str)",
6287         "{      static char laststr[256];",
6288         "       int is_cycle;",
6289         "",
6290         "       if (unwinding) return; /* 1.4.2 */",
6291         "       if (strncmp(str, laststr, 254))",
6292         "#if NCORE>1",
6293         "       cpu_printf(\"pan:%%d: %%s (at depth %%ld)\\n\", errors+1, str,",
6294         "#else",
6295         "       printf(\"pan:%%d: %%s (at depth %%ld)\\n\", errors+1, str,",
6296         "#endif",
6297         "#if NCORE>1",
6298         "               (nr_handoffs * z_handoff) + ",
6299         "#endif",
6300         "               ((depthfound == -1)?depth:depthfound));",
6301         "       strncpy(laststr, str, 254);",
6302         "       errors++;",
6303         "#ifdef HAS_CODE",
6304         "       if (readtrail) { wrap_trail(); return; }",
6305         "#endif",
6306         "       is_cycle = (strstr(str, \" cycle\") != (char *) 0);",
6307         "       if (!is_cycle)",
6308         "       {       depth++; trpt++;",      /* include failed step */
6309         "       }",
6310         "       if ((every_error != 0)",
6311         "       ||  errors == upto)",
6312         "       {",
6313         "#if defined(MA) && !defined(SAFETY)",
6314         "               if (is_cycle)",
6315         "               {       int od = depth;",
6316         "                       unwinding = 1;",
6317         "                       depthfound = Unwind();",
6318         "                       unwinding = 0;",
6319         "                       depth = od;",
6320         "               }",
6321         "#endif",
6322         "#if NCORE>1",
6323         "               writing_trail = 1;",
6324         "#endif",
6325         "#ifdef BFS",
6326         "               if (depth > 1) trpt--;",
6327         "               nuerror();",
6328         "               if (depth > 1) trpt++;",
6329         "#else",
6330         "               putrail();",
6331         "#endif",
6332         "#if defined(MA) && !defined(SAFETY)",
6333         "               if (strstr(str, \" cycle\"))",
6334         "               {       if (every_error)",
6335         "                       printf(\"sorry: MA writes 1 trail max\\n\");",
6336         "                       wrapup(); /* no recovery from unwind */",
6337         "               }",
6338         "#endif",
6339         "#if NCORE>1",
6340         "               if (search_terminated != NULL)",
6341         "               {       *search_terminated |= 4; /* uerror */",
6342         "               }",
6343         "               writing_trail = 0;",
6344         "#endif",
6345         "       }",
6346         "       if (!is_cycle)",
6347         "       {       depth--; trpt--;        /* undo */",
6348         "       }",
6349         "#ifndef BFS",
6350         "       if (iterative != 0 && maxdepth > 0)",
6351         "       {       if (maxdepth > depth)",
6352         "               {       maxdepth = (iterative == 1)?(depth+1):(depth/2);",
6353         "               }",
6354         "               warned = 1;",
6355         "               printf(\"pan: reducing search depth to %%ld\\n\",",
6356         "                       maxdepth);",
6357         "       } else",
6358         "#endif",
6359         "       if (errors >= upto && upto != 0)",
6360         "       {",
6361         "#ifdef BFS_PAR",
6362         "               bfs_shutdown(\"uerror\"); /* no return */",
6363         "#endif",
6364         "#if NCORE>1",
6365         "               sudden_stop(\"uerror\");",
6366         "#endif",
6367         "               wrapup();",
6368         "       }",
6369         "       depthfound = -1;",
6370         "}\n",
6371         "int",
6372         "xrefsrc(int lno, S_F_MAP *mp, int M, int i)",
6373         "{      Trans *T; int j, retval=1;",
6374         "       for (T = trans[M][i]; T; T = T->nxt)",
6375         "       if (T && T->tp)",
6376         "       {       if (strcmp(T->tp, \".(goto)\") == 0",
6377         "               ||  strncmp(T->tp, \"goto :\", 6) == 0)",
6378         "                       return 1; /* not reported */",
6379         "",
6380         "               for (j = 0; j < sizeof(mp); j++)",
6381         "                       if (i >= mp[j].from && i <= mp[j].upto)",
6382         "                       {       printf(\"\\t%%s:%%d\", mp[j].fnm, lno);",
6383         "                               break;",
6384         "                       }",
6385         "               if (j >= sizeof(mp))    /* fnm not found in list */",
6386         "               {       printf(\"\\t%%s:%%d\", PanSource, lno); /* use default */",
6387         "               }",
6388         "               printf(\", state %%d\", i);",
6389         "               if (strcmp(T->tp, \"\") != 0)",
6390         "               {       char *q;",
6391         "                       q = transmognify(T->tp);",
6392         "                       printf(\", \\\"%%s\\\"\", q?q:\"\");",
6393         "               } else if (stopstate[M][i])",
6394         "                       printf(\", -end state-\");",
6395         "               printf(\"\\n\");",
6396         "               retval = 0; /* reported */",
6397         "       }",
6398         "       return retval;",
6399         "}\n",
6400         "void",
6401         "r_ck(uchar *which, int N, int M, short *src, S_F_MAP *mp)",
6402         "{      int i, m=0;",
6403         "",
6404         "       if ((enum btypes) Btypes[M] == N_CLAIM",
6405         "       && claimname != NULL && strcmp(claimname, procname[M]) != 0)",
6406         "       {       return;",
6407         "       }",
6408         "",
6409         "       switch ((enum btypes) Btypes[M]) {",
6410         "       case P_PROC:",
6411         "       case A_PROC:",
6412         "               printf(\"unreached in proctype %%s\\n\", procname[M]);",
6413         "               break;",
6414         "       case I_PROC:",
6415         "               printf(\"unreached in init\\n\");",
6416         "               break;",
6417         "       case E_TRACE:",
6418         "       case N_TRACE:",
6419         "       case N_CLAIM:",
6420         "       default:",
6421         "               printf(\"unreached in claim %%s\\n\", procname[M]);",
6422         "               break;",
6423         "       }",
6424         "       for (i = 1; i < N; i++)",
6425         "       {       if (which[i] == 0",
6426         "               &&  (mapstate[M][i] == 0",
6427         "               ||   which[mapstate[M][i]] == 0))",
6428         "               {       m += xrefsrc((int) src[i], mp, M, i);",
6429         "               } else",
6430         "               {       m++;",
6431         "       }       }",
6432         "       printf(\"\t(%%d of %%d states)\\n\", N-1-m, N-1);",
6433         "}",
6434         "#if NCORE>1 && !defined(SEP_STATE)",
6435         "static long rev_trail_cnt;",
6436         "",
6437         "#ifdef FULL_TRAIL",
6438         "void",
6439         "rev_trail(int fd, volatile Stack_Tree *st_tr)",
6440         "{      long j; char snap[64];",
6441         "",
6442         "       if (!st_tr)",
6443         "       {       return;",
6444         "       }",
6445         "       rev_trail(fd, st_tr->prv);",
6446         "#ifdef VERBOSE",
6447         "       printf(\"%%d (%%d) LRT [%%d,%%d] -- %%9u (root %%9u)\\n\",",
6448         "               depth, rev_trail_cnt, st_tr->pr, st_tr->t_id, st_tr, stack_last[core_id]);",
6449         "#endif",
6450         "       if (st_tr->pr != 255)", /* still needed? */
6451         "       {       sprintf(snap, \"%%ld:%%d:%%d\\n\", ",
6452         "                       rev_trail_cnt++, st_tr->pr, st_tr->t_id);",
6453         "               j = strlen(snap);",
6454         "               if (write(fd, snap, j) != j)",
6455         "               {       printf(\"pan: error writing trailfile\\n\");",
6456         "                       close(fd);",
6457         "                       wrapup();",
6458         "                       return;",
6459         "               }",
6460         "       } else  /* handoff point */",
6461         "       {       if (a_cycles)",
6462         "               {       (void) write(fd, \"-1:-1:-1\\n\", 9);",
6463         "       }       }",
6464         "}",
6465         "#endif", /* FULL_TRAIL */
6466         "#endif", /* NCORE>1 */
6467         "",
6468         "void",
6469         "putrail(void)",
6470         "{      int fd;",
6471         "#if defined VERI || defined(MERGED)",
6472         "       char snap[64];",
6473         "#endif",
6474         "#if NCORE==1 || defined(SEP_STATE) || !defined(FULL_TRAIL)",
6475         "       long i, j;",
6476         "       Trail *trl;",
6477         "#endif",
6478         "       fd = make_trail();",
6479         "       if (fd < 0) return;",
6480         "#ifdef VERI",
6481         "       sprintf(snap, \"-2:%%d:-2\\n\", (uchar) ((P0 *)pptr(0))->_t);",
6482         "       if (write(fd, snap, strlen(snap)) < 0) return;",
6483         "#endif",
6484         "#ifdef MERGED",
6485         "       sprintf(snap, \"-4:-4:-4\\n\");",
6486         "       if (write(fd, snap, strlen(snap)) < 0) return;",
6487         "#endif",
6488         "#ifdef PERMUTED",
6489         "       sprintf(snap, \"-5:%%d:%%d\\n\", t_reverse, reversing&2);",
6490         "       if (write(fd, snap, strlen(snap)) < 0) return;",
6491         "",
6492         "       sprintf(snap, \"-6:%%d:%%d\\n\", p_reorder==set_permuted, p_reorder==set_reversed);",
6493         "       if (write(fd, snap, strlen(snap)) < 0) return;",
6494         "",
6495         "       sprintf(snap, \"-7:%%d:%%d\\n\", p_reorder==set_rotated, p_rotate);",
6496         "       if (write(fd, snap, strlen(snap)) < 0) return;",
6497         "",
6498         "       sprintf(snap, \"-8:%%d:%%d\\n\", p_reorder==set_randrot, --s_rand);",
6499         "       if (write(fd, snap, strlen(snap)) < 0) return;",
6500         "#endif",
6501         "#if NCORE>1 && !defined(SEP_STATE) && defined(FULL_TRAIL)",
6502         "       rev_trail_cnt = 1;",
6503         "       enter_critical(GLOBAL_LOCK);",
6504         "        rev_trail(fd, stack_last[core_id]);",
6505         "       leave_critical(GLOBAL_LOCK);",
6506         "#else",
6507         "       i = 1; /* trail starts at position 1 */",
6508         "       #if NCORE>1 && defined(SEP_STATE)",
6509         "       if (cur_Root.m_vsize > 0) { i++; depth++; }",
6510         "       #endif",
6511         "       for ( ; i <= depth; i++)",
6512         "       {       if (i == depthfound+1)",
6513         "               {       if (write(fd, \"-1:-1:-1\\n\", 9) != 9)",
6514         "                       {       goto notgood;",
6515         "               }       }",
6516         "               trl = getframe(i);",
6517         "               if (!trl->o_t) continue;",
6518         "               if (trl->o_pm&128) continue;",
6519         "               sprintf(snap, \"%%ld:%%d:%%d\\n\", ",
6520         "                       i, trl->pr, trl->o_t->t_id);",
6521         "               j = strlen(snap);",
6522         "               if (write(fd, snap, j) != j)",
6523         "               {",
6524         "notgood:               printf(\"pan: error writing trailfile\\n\");",
6525         "                       close(fd);",
6526         "                       wrapup();",
6527         "       }       }",
6528         "#endif",
6529         "       close(fd);",
6530         "#if NCORE>1",
6531         "       cpu_printf(\"pan: wrote trailfile\\n\");",
6532         "#endif",
6533         "}\n",
6534         "void",
6535         "sv_save(void)  /* push state vector onto save stack */",
6536         "{      if (!svtack->nxt)",
6537         "       {  svtack->nxt = (Svtack *) emalloc(sizeof(Svtack));",
6538         "          svtack->nxt->body = emalloc(vsize*sizeof(char));",
6539         "          svtack->nxt->lst = svtack;",
6540         "          svtack->nxt->m_delta = vsize;",
6541         "          svmax++;",
6542         "       } else if (vsize > svtack->nxt->m_delta)",
6543         "       {  svtack->nxt->body = emalloc(vsize*sizeof(char));",
6544         "          svtack->nxt->lst = svtack;",
6545         "          svtack->nxt->m_delta = vsize;",
6546         "          svmax++;",
6547         "       }",
6548         "       svtack = svtack->nxt;",
6549         "#if SYNC",
6550         "       svtack->o_boq = boq;",
6551         "#endif",
6552         "#ifdef TRIX",
6553         "       sv_populate();",
6554         "#endif",
6555         "       svtack->o_delta = vsize; /* don't compress */",
6556         "       memcpy((char *)(svtack->body), (char *) &now, vsize);",
6557         "#if defined(C_States) && defined(HAS_STACK) && (HAS_TRACK==1)",
6558         "       c_stack((uchar *) &(svtack->c_stack[0]));",
6559         "#endif",
6560         "#ifdef DEBUG",
6561         "       cpu_printf(\"%%d:       sv_save\\n\", depth);",
6562         "#endif",
6563         "}\n",
6564         "void",
6565         "sv_restor(void)        /* pop state vector from save stack */",
6566         "{",
6567         "       memcpy((char *)&now, svtack->body, svtack->o_delta);",
6568         "#if SYNC",
6569         "       boq = svtack->o_boq;",
6570         "#endif",
6571         "#ifdef TRIX",
6572         "       re_populate();",
6573         "#endif",
6574         "#if defined(C_States) && (HAS_TRACK==1)",
6575         "#ifdef HAS_STACK",
6576         "       c_unstack((uchar *) &(svtack->c_stack[0]));",
6577         "#endif",
6578         "       c_revert((uchar *) &(now.c_state[0]));",
6579         "#endif",
6580
6581         "       if (vsize != svtack->o_delta)",
6582         "               Uerror(\"sv_restor\");",
6583         "       if (!svtack->lst)",
6584         "               Uerror(\"error: sv_restor\");",
6585         "       svtack  = svtack->lst;",
6586         "#ifdef DEBUG",
6587         "       cpu_printf(\"   sv_restor\\n\");",
6588         "#endif",
6589         "}",
6590         "",
6591         "void",
6592         "p_restor(int h)",
6593         "{      int i;",
6594         "       char *z = (char *) &now;\n",
6595         "",
6596         "#ifdef BFS_PAR",
6597         "       bfs_prepmask(1);        /* p_restor */",
6598         "#endif",
6599         "#ifndef TRIX",
6600         "       proc_offset[h] = stack->o_offset;",
6601         "       proc_skip[h]   = (uchar) stack->o_skip;",
6602         "#else",
6603         "       char *oi;",
6604         "       #ifdef V_TRIX",
6605         "               printf(\"%%4d: p_restor %%d\\n\", depth, h);",
6606         "       #endif",
6607         "#endif",
6608         "#ifndef XUSAFE",
6609         "       p_name[h] = stack->o_name;",
6610         "#endif",
6611         "#ifdef TRIX",
6612         "       vsize += sizeof(char *);",
6613         "       #ifndef BFS",
6614         "               if (processes[h] != NULL || freebodies == NULL)",
6615         "               {       Uerror(\"processes error\");",
6616         "               }",
6617         "               processes[h] = freebodies;",
6618         "               freebodies = freebodies->nxt;",
6619         "               processes[h]->nxt = (TRIX_v6 *) 0;",
6620         "               processes[h]->modified = 1;     /* p_restor */",
6621         "       #endif",
6622         "       processes[h]->parent_pid = stack->parent;",
6623         "       processes[h]->psize = stack->o_delta;",
6624         "       memcpy((char *)pptr(h), stack->b_ptr, stack->o_delta);",
6625         "       oi = stack->b_ptr;",
6626         "#else",
6627         "       #if !defined(NOCOMP) && !defined(HC)",
6628         "       for (i = vsize + stack->o_skip; i > vsize; i--)",
6629         "               Mask[i-1] = 1; /* align */",
6630         "       #endif",
6631         "       vsize += stack->o_skip;",
6632         "       memcpy(z+vsize, stack->body, stack->o_delta);",
6633         "       vsize += stack->o_delta;",
6634         "       #if !defined(NOCOMP) && !defined(HC)",
6635         "               for (i = 1; i <= Air[((P0 *)pptr(h))->_t]; i++)",
6636         "                       Mask[vsize - i] = 1;    /* pad */",
6637         "               Mask[proc_offset[h]] = 1;       /* _pid */",
6638         "       #endif",
6639         "       if (BASE > 0 && h > 0)",
6640         "               ((P0 *)pptr(h))->_pid = h-BASE;",
6641         "       else",
6642         "               ((P0 *)pptr(h))->_pid = h;",
6643         "       #ifdef BFS_PAR",
6644         "               bfs_fixmask(1); /* p_restor */",
6645         "       #endif",
6646         "#endif",
6647         "       now._nr_pr += 1;",
6648         "#ifndef NOVSZ",
6649         "       now._vsz = vsize;",
6650         "#endif",
6651         "       i = stack->o_delqs;",
6652         "       if (!stack->lst)",
6653         "               Uerror(\"error: p_restor\");",
6654         "       stack = stack->lst;",
6655         "       this = pptr(h);",
6656         "       while (i-- > 0)",
6657         "               q_restor();",
6658         "#ifdef TRIX",
6659         "       re_mark_all(1); /* p_restor - all chans move up in _ids_ */",
6660         "       now._ids_[h] = oi; /* restor the original contents */",
6661         "#endif",
6662         "}\n",
6663         "void",
6664         "q_restor(void)",
6665         "{      int h = now._nr_qs;",
6666         "#ifdef TRIX",
6667         "       #ifdef V_TRIX",
6668         "               printf(\"%%4d: q_restor %%d\\n\", depth, h);",
6669         "       #endif",
6670         "       vsize += sizeof(char *);",
6671         "       #ifndef BFS",
6672         "               if (channels[h] != NULL || freebodies == NULL)",
6673         "               {       Uerror(\"channels error\");",
6674         "               }",
6675         "               channels[h] = freebodies;",
6676         "               freebodies = freebodies->nxt;",
6677         "               channels[h]->nxt = (TRIX_v6 *) 0;",
6678         "               channels[h]->modified = 1;      /* q_restor */",
6679         "       #endif",
6680         "       channels[h]->parent_pid = stack->parent;",
6681         "       channels[h]->psize = stack->o_delta;",
6682         "       memcpy((char *)qptr(h), stack->b_ptr, stack->o_delta);",
6683         "       now._ids_[now._nr_pr + h] = stack->b_ptr;",
6684         "#else",
6685         "       char *z = (char *) &now;",
6686         "       #ifndef NOCOMP",
6687         "               int k, k_end;",
6688         "       #endif",
6689         "       #ifdef BFS_PAR",
6690         "               bfs_prepmask(2);        /* q_restor */",
6691         "       #endif",
6692         "       q_offset[h] = stack->o_offset;",
6693         "       q_skip[h]   = (uchar) stack->o_skip;",
6694         "       vsize += stack->o_skip;",
6695         "       memcpy(z+vsize, stack->body, stack->o_delta);",
6696         "       vsize += stack->o_delta;",
6697         "#endif",
6698         "#ifndef XUSAFE",
6699         "       q_name[h] = stack->o_name;",
6700         "#endif",
6701         "#ifndef NOVSZ",
6702         "       now._vsz = vsize;",
6703         "#endif",
6704         "       now._nr_qs += 1;",
6705         "#ifndef TRIX",
6706         "       #if !defined(NOCOMP) && !defined(HC)",
6707         "               k_end = stack->o_offset;",
6708         "               k = k_end - stack->o_skip;",
6709         "               #if SYNC",
6710         "                       #ifndef BFS",
6711         "                       if (q_zero(now._nr_qs)) k_end += stack->o_delta;",
6712         "                       #endif",
6713         "               #endif",
6714         "               for ( ; k < k_end; k++)",
6715         "                       Mask[k] = 1;",
6716         "       #endif",
6717         "       #ifdef BFS_PAR",
6718         "               bfs_fixmask(2); /* q_restor */",
6719         "       #endif",
6720         "#endif",
6721         "       if (!stack->lst)",
6722         "               Uerror(\"error: q_restor\");",
6723         "       stack = stack->lst;",
6724         "}",
6725
6726         "typedef struct IntChunks {",
6727         "       int     *ptr;",
6728         "       struct  IntChunks *nxt;",
6729         "} IntChunks;",
6730         "IntChunks *filled_chunks[512];",
6731         "IntChunks *empty_chunks[512];",
6732
6733         "int *",
6734         "grab_ints(int nr)",
6735         "{      IntChunks *z;",
6736         "       if (nr >= 512) Uerror(\"cannot happen grab_int\");",
6737         "       if (filled_chunks[nr])",
6738         "       {       z = filled_chunks[nr];",
6739         "               filled_chunks[nr] = filled_chunks[nr]->nxt;",
6740         "       } else ",
6741         "       {       z = (IntChunks *) emalloc(sizeof(IntChunks));",
6742         "               z->ptr = (int *) emalloc(nr * sizeof(int));",
6743         "       }",
6744         "       z->nxt = empty_chunks[nr];",
6745         "       empty_chunks[nr] = z;",
6746         "       return z->ptr;",
6747         "}",
6748         "void",
6749         "ungrab_ints(int *p, int nr)",
6750         "{      IntChunks *z;",
6751         "       if (!empty_chunks[nr]) Uerror(\"cannot happen ungrab_int\");",
6752         "       z = empty_chunks[nr];",
6753         "       empty_chunks[nr] = empty_chunks[nr]->nxt;",
6754         "       z->ptr = p;",
6755         "       z->nxt = filled_chunks[nr];",
6756         "       filled_chunks[nr] = z;",
6757         "}",
6758         "int",
6759         "delproc(int sav, int h)",
6760         "{      int d, i=0;",
6761         "#ifndef NOCOMP",
6762         "       int o_vsize = vsize;",
6763         "#endif",
6764         "       if (h+1 != (int) now._nr_pr)",
6765         "       {       return 0;",
6766         "       }",
6767         "#ifdef TRIX",
6768         "       #ifdef V_TRIX",
6769         "               printf(\"%%4d: delproc %%d -- parent %%d\\n\", depth, h, processes[h]->parent_pid);",
6770         "               if (now._nr_qs > 0)",
6771         "               printf(\"       top channel: %%d -- parent %%d\\n\", now._nr_qs-1, channels[now._nr_qs-1]->parent_pid);",
6772         "       #endif",
6773         "       while (now._nr_qs > 0",
6774         "       &&     channels[now._nr_qs-1]->parent_pid == processes[h]->parent_pid)",
6775         "       {       delq(sav);",
6776         "               i++;",
6777         "       }",
6778         "       d = processes[h]->psize;",
6779         "       if (sav)",
6780         "       {       if (!stack->nxt)",
6781         "               {       stack->nxt = (_Stack *) emalloc(sizeof(_Stack));",
6782         "                       stack->nxt->lst = stack;",
6783         "                       smax++;",
6784         "               }",
6785         "               stack = stack->nxt;",
6786         "       #ifndef XUSAFE",
6787         "               stack->o_name   = p_name[h];",
6788         "       #endif",
6789         "               stack->parent   = processes[h]->parent_pid;",
6790         "               stack->o_delta  = d;",
6791         "               stack->o_delqs  = i;",
6792         "               stack->b_ptr = now._ids_[h];", /* new 6.1 */
6793         "       }",
6794         "       memset((char *)pptr(h), 0, d);",
6795         "       #ifndef BFS",
6796         "               processes[h]->nxt = freebodies;",
6797         "               freebodies = processes[h];",
6798         "               processes[h] = (TRIX_v6 *) 0;",
6799         "       #endif",
6800         "       vsize -= sizeof(char *);",
6801         "       now._nr_pr -= 1;",
6802         "       re_mark_all(-1); /* delproc - all chans move down in _ids_ */",
6803         "#else",
6804         "       while (now._nr_qs",
6805         "       &&     q_offset[now._nr_qs-1] > proc_offset[h])",
6806         "       {       delq(sav);",
6807         "               i++;",
6808         "       }",
6809         "       d = vsize - proc_offset[h];",
6810         "       if (sav)",
6811         "       {       if (!stack->nxt)",
6812         "               {       stack->nxt = (_Stack *) emalloc(sizeof(_Stack));",
6813         "                       stack->nxt->body = emalloc(Maxbody * sizeof(char));",
6814         "                       stack->nxt->lst = stack;",
6815         "                       smax++;",
6816         "               }",
6817         "               stack = stack->nxt;",
6818         "               stack->o_offset = proc_offset[h];",
6819         "       #if VECTORSZ>32000",
6820         "               stack->o_skip   = (int) proc_skip[h];",
6821         "       #else",
6822         "               stack->o_skip   = (short) proc_skip[h];",
6823         "       #endif",
6824         "       #ifndef XUSAFE",
6825         "               stack->o_name   = p_name[h];",
6826         "       #endif",
6827         "               stack->o_delta  = d;",
6828         "               stack->o_delqs  = i;",
6829         "               memcpy(stack->body, (char *)pptr(h), d);",
6830         "       }",
6831         "       vsize = proc_offset[h];",
6832         "       now._nr_pr -= 1;",
6833         "       memset((char *)pptr(h), 0, d);",
6834         "       vsize -= (int) proc_skip[h];",
6835         "       #if !defined(NOCOMP) && !defined(HC)",
6836         "               #ifdef BFS_PAR",
6837         "                       bfs_prepmask(3); /* delproc - no chance in proc_offset or proc_skip */",
6838         "               #endif",
6839         "               for (i = vsize; i < o_vsize; i++)",
6840         "                       Mask[i] = 0; /* reset */",
6841         "               #ifdef BFS_PAR",
6842         "                       bfs_fixmask(3); /* delproc */",
6843         "               #endif",
6844         "       #endif",
6845         "#endif",
6846         "#ifndef NOVSZ",
6847         "       now._vsz = vsize;",
6848         "#endif",
6849         "       return 1;",
6850         "}\n",
6851         "void",
6852         "delq(int sav)",
6853         "{      int h = now._nr_qs - 1;",
6854         "#ifdef TRIX",
6855         "       int d = channels[now._nr_qs - 1]->psize;",
6856         "#else",
6857         "       int d = vsize - q_offset[now._nr_qs - 1];",
6858         "#endif",
6859         "#ifndef NOCOMP",
6860         "       int k, o_vsize = vsize;",
6861         "#endif",
6862         "       if (sav)",
6863         "       {       if (!stack->nxt)",
6864         "               {       stack->nxt = (_Stack *) emalloc(sizeof(_Stack));",
6865         "#ifndef TRIX",
6866         "                       stack->nxt->body = emalloc(Maxbody * sizeof(char));",
6867         "#endif",
6868         "                       stack->nxt->lst = stack;",
6869         "                       smax++;",
6870         "               }",
6871         "               stack = stack->nxt;",
6872         "#ifdef TRIX",
6873         "               stack->parent = channels[h]->parent_pid;",
6874         "               stack->b_ptr = now._ids_[h];", /* new 6.1 */
6875         "#else",
6876         "               stack->o_offset = q_offset[h];",
6877         "       #if VECTORSZ>32000",
6878         "               stack->o_skip   = (int) q_skip[h];",
6879         "       #else",
6880         "               stack->o_skip   = (short) q_skip[h];",
6881         "       #endif",
6882         "#endif",
6883         "       #ifndef XUSAFE",
6884         "               stack->o_name   = q_name[h];",
6885         "       #endif",
6886         "               stack->o_delta  = d;",
6887         "#ifndef TRIX",
6888         "               memcpy(stack->body, (char *)qptr(h), d);",
6889         "#endif",
6890         "       }",
6891         "#ifdef TRIX",
6892         "       vsize -= sizeof(char *);",
6893         "       #ifdef V_TRIX",
6894         "               printf(\"%%4d: delq %%d parent %%d\\n\", depth, h, channels[h]->parent_pid);",
6895         "       #endif",
6896         "#else",
6897         "       vsize = q_offset[h];",
6898         "       vsize -= (int) q_skip[h];",
6899         "       #if !defined(NOCOMP) && !defined(HC)",
6900         "               #ifdef BFS_PAR",
6901         "                       bfs_prepmask(3); /* delq - no change in q_offset or q_skip */",
6902         "               #endif",
6903         "               for (k = vsize; k < o_vsize; k++)",
6904         "                       Mask[k] = 0; /* reset */",
6905         "               #ifdef BFS_PAR",
6906         "                       bfs_fixmask(3); /* delq */",
6907         "               #endif",
6908         "       #endif",
6909         "#endif",
6910         "       now._nr_qs -= 1;",
6911         "       memset((char *)qptr(h), 0, d);",
6912         "#ifdef TRIX",
6913         "       #ifndef BFS",
6914         "               channels[h]->nxt = freebodies;",
6915         "               freebodies = channels[h];",
6916         "               channels[h] = (TRIX_v6 *) 0;",
6917         "       #endif",
6918         "#endif",
6919         "#ifndef NOVSZ",
6920         "       now._vsz = vsize;",
6921         "#endif",
6922         "}\n",
6923         "int",
6924         "qs_empty(void)",
6925         "{      int i;",
6926         "       for (i = 0; i < (int) now._nr_qs; i++)",
6927         "       {       if (q_sz(i) > 0)",
6928         "                       return 0;",
6929         "       }",
6930         "       return 1;",
6931         "}\n",
6932         "int",
6933         "endstate(void)",
6934         "{      int i; P0 *ptr;",
6935         "       for (i = BASE; i < (int) now._nr_pr; i++)",
6936         "       {       ptr = (P0 *) pptr(i);",
6937         "               if (!stopstate[ptr->_t][ptr->_p])",
6938         "                       return 0;",
6939         "       }",
6940         "       if (strict) return qs_empty();",
6941         "#if defined(EVENT_TRACE)",
6942         "       if (!stopstate[EVENT_TRACE][now._event] && !a_cycles)",
6943         "       {       printf(\"pan: event_trace not completed\\n\");",
6944         "               return 0;",
6945         "       }",
6946         "#endif",
6947         "       return 1;",
6948         "}\n",
6949         "#if !defined(SAFETY) && !defined(BFS)",
6950         "void",
6951         "checkcycles(void)",
6952         "{      uchar o_a_t = now._a_t;",
6953         "       #ifndef NOFAIR",
6954         "               uchar o_cnt = now._cnt[1];",
6955         "       #endif",
6956         "       #ifdef FULLSTACK",
6957         "               #ifndef MA",
6958         "                       H_el *sv = trpt->ostate; /* save */",
6959         "               #else",
6960         "                       uchar prov = trpt->proviso; /* save */",
6961         "               #endif",
6962         "       #endif",
6963         "       #ifdef DEBUG",
6964         "        {      int i; uchar *v = (uchar *) &now;",
6965         "               printf(\"       set Seed state \");",
6966         "               #ifndef NOFAIR",
6967         "                       if (fairness)",
6968         "                               printf(\"(cnt = %%d:%%d, nrpr=%%d) \",",
6969         "                               now._cnt[0], now._cnt[1], now._nr_pr);",
6970         "               #endif",
6971         "               /* for (i = 0; i < n; i++) printf(\"%%d,\", v[i]); */",
6972         "               printf(\"\\n\");",
6973         "        }",
6974         "        printf(\"%%ld: cycle check starts\\n\", depth);",
6975         "       #endif",
6976         "       now._a_t |= (1|16|32);",
6977         "       /* 1 = 2nd DFS; (16|32) to improve hashing */",
6978         "       #ifndef NOFAIR",
6979         "               now._cnt[1] = now._cnt[0];",
6980         "       #endif",
6981         "       memcpy((char *)&A_Root, (char *)&now, vsize);",
6982         "       A_depth = depthfound = depth;",
6983
6984         "       #if NCORE>1",
6985         "               mem_put_acc();", /* handoff accept states */
6986         "       #else",
6987         "               new_state();    /* start 2nd DFS */",
6988         "       #endif",
6989
6990         "       now._a_t = o_a_t;",
6991         "       #ifndef NOFAIR",
6992         "               now._cnt[1] = o_cnt;",
6993         "       #endif",
6994         "       A_depth = 0; depthfound = -1;",
6995                 "#ifdef DEBUG",
6996         "       printf(\"%%ld: cycle check returns\\n\", depth);",
6997                 "#endif",
6998                 "#ifdef FULLSTACK",
6999                 "#ifndef MA",
7000         "       trpt->ostate = sv;      /* restore */",
7001                 "#else",
7002         "       trpt->proviso = prov;",
7003                 "#endif",
7004                 "#endif",
7005         "}",
7006         "#endif",
7007         "",
7008         "#if defined(FULLSTACK) && defined(BITSTATE)",
7009         "H_el *Free_list = (H_el *) 0;",
7010         "void",
7011         "onstack_init(void)     /* to store stack states in a bitstate search */",
7012         "{      S_Tab = (H_el **) emalloc(maxdepth*sizeof(H_el *));",
7013         "}",
7014         "#endif",
7015
7016         "#if !defined(BFS_PAR)",
7017         " #if defined(FULLSTACK) && defined(BITSTATE)",
7018                 "H_el *",
7019                 "grab_state(int n)",
7020                 "{      H_el *v, *last = 0;",
7021                 "       if (H_tab == S_Tab)",
7022                 "       {       for (v = Free_list; v && ((int) v->tagged >= n); v=v->nxt)",
7023                 "               {       if ((int) v->tagged == n)",
7024                 "                       {       if (last)",
7025                 "                                       last->nxt = v->nxt;",
7026                 "                               else",
7027                 "gotcha:                                Free_list = v->nxt;",
7028                 "                               v->tagged = 0;",
7029                 "                               v->nxt = 0;",
7030                 "       #ifdef COLLAPSE",
7031                 "                               v->ln = 0;",
7032                 "       #endif",
7033                 "                               return v;",
7034                 "                       }",
7035                 "                       Fh++; last=v;",
7036                 "               }",
7037                 "               /* new: second try */",
7038                 "               v = Free_list;", /* try to avoid emalloc */
7039                 "               if (v && ((int) v->tagged >= n))",
7040                 "                       goto gotcha;",
7041                 "               ngrabs++;",
7042                 "       }",
7043                 "       return (H_el *) emalloc(sizeof(H_el)+n-sizeof(unsigned));",
7044                 "}",
7045         " #else",               /* !FULLSTACK || !BITSTATE */
7046                 "#if NCORE>1",
7047                         "H_el *",
7048                         "grab_state(int n)",
7049                         "{      H_el *grab_shared(int);",
7050                         "       return grab_shared(sizeof(H_el)+n-sizeof(unsigned));",
7051                         "}",
7052                 "#else", /* ! NCORE>1 */
7053                         "#ifndef AUTO_RESIZE",
7054                         "       #define grab_state(n) (H_el *) \\",
7055                         "               emalloc(sizeof(H_el)+n-sizeof(ulong));",
7056                         "#else",        /* AUTO_RESIZE */
7057                         "H_el *",
7058                         "grab_state(int n)",
7059                         "{      H_el *p;",
7060                         "       int cnt = sizeof(H_el)+n-sizeof(ulong);",
7061                         "#ifndef MA",
7062                         "       if (reclaim_size >= cnt+WS)",
7063                         "       {       if ((cnt & (WS-1)) != 0) /* alignment */",
7064                         "               {       cnt += WS - (cnt & (WS-1));",
7065                         "               }",
7066                         "               p = (H_el *) reclaim_mem;",
7067                         "               reclaim_mem  += cnt;",
7068                         "               reclaim_size -= cnt;",
7069                         "               memset(p, 0, cnt);",
7070                         "       } else",
7071                         "#endif",
7072                         "       {       p = (H_el *) emalloc(cnt);",
7073                         "       }",
7074                         "       return p;",
7075                         "}",
7076                         "#endif",       /* AUTO_RESIZE */
7077                 "#endif",               /* NCORE>1 */
7078         " #endif",                      /* FULLSTACK && !BITSTATE */
7079         "#else", /* BFS_PAR */
7080         "       extern volatile uchar *sh_pre_malloc(ulong);",
7081         "       extern volatile uchar *sh_malloc(ulong);",
7082         "       H_el *",
7083         "       grab_state(int n)       /* bfs_par */",
7084         "       {       volatile uchar *rval = NULL;",
7085         "               int m = sizeof(H_el) + n - sizeof(unsigned);",
7086         "",
7087         "               if (n == 0) m = m/n;",
7088         "       #ifdef BFS_SEP_HASH",
7089         "               rval = emalloc((ulong) m);",
7090         "       #else",
7091         "               rval = sh_malloc((ulong) m);",
7092         "       #endif",
7093         "               memset((void *) rval, 0, (size_t) m);",
7094         "",
7095         "               return (H_el *) rval;",
7096         "       }",
7097         "#endif", /* BFS_PAR */
7098
7099 "#ifdef COLLAPSE",
7100         "ulong",
7101         "ordinal(char *v, long n, short tp)",
7102         "{      H_el *tmp, *ntmp; long m;",
7103         "       H_el *olst = (H_el *) 0;",
7104         "       s_hash((uchar *)v, n);",
7105
7106         "#if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
7107         "       e_critical(BFS_ID);     /* bfs_par / collapse */",
7108         "#endif",
7109         "#if NCORE>1 && !defined(SEP_STATE)",
7110         "       enter_critical(CS_ID);  /* uses spinlock - 1..128 */",
7111         "#endif",
7112         "       tmp = H_tab[j1_spin];",
7113         "       if (!tmp)",
7114         "       {       tmp = grab_state(n);",
7115         "               H_tab[j1_spin] = tmp;",
7116         "       } else",
7117         "       for ( ;; olst = tmp, tmp = tmp->nxt)",
7118         "       {       if (n == tmp->ln)",
7119         "               {       m = memcmp(((char *)&(tmp->state)), v, n);",
7120         "                       if (m == 0)",
7121         "                               goto done;",
7122         "                       if (m < 0)",
7123         "                       {",
7124         "Insert:                        ntmp = grab_state(n);",
7125         "                               ntmp->nxt = tmp;",
7126         "                               if (!olst)",
7127         "                                       H_tab[j1_spin] = ntmp;",
7128         "                               else",
7129         "                                       olst->nxt = ntmp;",
7130         "                               tmp = ntmp;",
7131         "                               break;",
7132         "                       } else if (!tmp->nxt)",
7133         "                       {",
7134         "Append:                        tmp->nxt = grab_state(n);",
7135         "                               tmp = tmp->nxt;",
7136         "                               break;",
7137         "                       }",
7138         "                       continue;",
7139         "               }",
7140         "               if (n < tmp->ln)",
7141         "                       goto Insert;",
7142         "               else if (!tmp->nxt)",
7143         "                       goto Append;",
7144         "       }",
7145         "#if NCORE>1 && !defined(SEP_STATE)",
7146         "       enter_critical(GLOBAL_LOCK);",
7147         "#endif",
7148         "#ifdef BFS_PAR",
7149         "       e_critical(BFS_ORD);    /* bfs_par */",
7150         "#endif",
7151         "       m = ++ncomps[tp];",
7152         "#ifdef BFS_PAR",
7153         "       x_critical(BFS_ORD);",
7154         "#endif",
7155         "#if NCORE>1 && !defined(SEP_STATE)",
7156         "       leave_critical(GLOBAL_LOCK);",
7157         "#endif",
7158         "#ifdef FULLSTACK",
7159         "       tmp->tagged = m;",
7160         "#else",
7161         "       tmp->st_id  = m;",
7162         "#endif",
7163         "#if defined(AUTO_RESIZE) && !defined(BITSTATE)",
7164         "       tmp->m_K1 = K1;",
7165         "#endif",
7166         "       memcpy(((char *)&(tmp->state)), v, n);",
7167         "       tmp->ln = n;",
7168         "done:",
7169
7170         "#if NCORE>1 && !defined(SEP_STATE)",
7171         "       leave_critical(CS_ID);",
7172         "#endif",
7173         "#if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
7174         "       x_critical(BFS_ID);",
7175         "#endif",
7176
7177         "#ifdef FULLSTACK",
7178         "       return tmp->tagged;",
7179         "#else",
7180         "       return tmp->st_id;",
7181         "#endif",
7182         "}",
7183         "",
7184         "int",
7185         "compress(char *vin, int nin)   /* collapse compression */",
7186         "{      char    *w, *v = (char *) &comp_now;",
7187         "       int     i, j;",
7188         "       ulong   n;",
7189         "       static char     *x;",
7190         "       static uchar    nbytes[513]; /* 1 + 256 + 256 */",
7191         "       static unsigned short nbytelen;",
7192         "       long col_q(int, char *);",
7193         "       long col_p(int, char *);",
7194         "#ifndef SAFETY",
7195         "       if (a_cycles)",
7196         "               *v++ = now._a_t;",
7197                 "#ifndef NOFAIR",
7198         "       if (fairness)",
7199         "       for (i = 0; i < NFAIR; i++)",
7200         "               *v++ = now._cnt[i];",
7201                 "#endif",
7202         "#endif",
7203         "       nbytelen = 0;",
7204
7205         "#ifndef JOINPROCS",
7206         "       for (i = 0; i < (int) now._nr_pr; i++)",
7207         "       {       n = col_p(i, (char *) 0);",
7208         "#ifdef NOFIX",
7209         "               nbytes[nbytelen] = 0;",
7210         "#else",
7211         "               nbytes[nbytelen] = 1;",
7212         "               *v++ = ((P0 *) pptr(i))->_t;",
7213         "#endif",
7214         "               *v++ = n&255;",
7215         "               if (n >= (1<<8))",
7216         "               {       nbytes[nbytelen]++;",
7217         "                       *v++ = (n>>8)&255;",
7218         "               }",
7219         "               if (n >= (1<<16))",
7220         "               {       nbytes[nbytelen]++;",
7221         "                       *v++ = (n>>16)&255;",
7222         "               }",
7223         "               if (n >= (1<<24))",
7224         "               {       nbytes[nbytelen]++;",
7225         "                       *v++ = (n>>24)&255;",
7226         "               }",
7227         "               nbytelen++;",
7228         "       }",
7229         "#else",
7230         "       x = scratch;",
7231         "       for (i = 0; i < (int) now._nr_pr; i++)",
7232         "               x += col_p(i, x);",
7233         "       n = ordinal(scratch, x-scratch, 2); /* procs */",
7234         "       *v++ = n&255;",
7235         "       nbytes[nbytelen] = 0;",
7236         "       if (n >= (1<<8))",
7237         "       {       nbytes[nbytelen]++;",
7238         "               *v++ = (n>>8)&255;",
7239         "       }",
7240         "       if (n >= (1<<16))",
7241         "       {       nbytes[nbytelen]++;",
7242         "               *v++ = (n>>16)&255;",
7243         "       }",
7244         "       if (n >= (1<<24))",
7245         "       {       nbytes[nbytelen]++;",
7246         "               *v++ = (n>>24)&255;",
7247         "       }",
7248         "       nbytelen++;",
7249         "#endif",
7250         "#ifdef SEPQS",
7251         "       for (i = 0; i < (int) now._nr_qs; i++)",
7252         "       {       n = col_q(i, (char *) 0);",
7253         "               nbytes[nbytelen] = 0;",
7254         "               *v++ = n&255;",
7255         "               if (n >= (1<<8))",
7256         "               {       nbytes[nbytelen]++;",
7257         "                       *v++ = (n>>8)&255;",
7258         "               }",
7259         "               if (n >= (1<<16))",
7260         "               {       nbytes[nbytelen]++;",
7261         "                       *v++ = (n>>16)&255;",
7262         "               }",
7263         "               if (n >= (1<<24))",
7264         "               {       nbytes[nbytelen]++;",
7265         "                       *v++ = (n>>24)&255;",
7266         "               }",
7267         "               nbytelen++;",
7268         "       }",
7269         "#endif",
7270
7271         "#ifdef NOVSZ",
7272         "       /* 3 = _a_t, _nr_pr, _nr_qs */",
7273         "       w = (char *) &now + 3 * sizeof(uchar);",
7274                 "#ifndef NOFAIR",
7275                 "       w += NFAIR;",
7276                 "#endif",
7277         "#else",
7278                 "#if VECTORSZ<65536",
7279                 "       w = (char *) &(now._vsz) + sizeof(unsigned short);",
7280                 "#else",
7281                 "       w = (char *) &(now._vsz) + sizeof(ulong);",
7282                 "#endif",
7283         "#endif",
7284         "       x = scratch;",
7285         "       *x++ = now._nr_pr;",
7286         "       *x++ = now._nr_qs;",
7287
7288         "       if (now._nr_qs > 0 && qptr(0) < pptr(0))",
7289         "               n = qptr(0) - (uchar *) w;",
7290         "       else",
7291         "               n = pptr(0) - (uchar *) w;",
7292         "       j = w - (char *) &now;",
7293         "",
7294         "#if !defined(NOCOMP) && !defined(HC)",
7295         "       for (i = 0; i < (int) n; i++, w++)",
7296         "               if (!Mask[j++]) *x++ = *w;",
7297         "#else",
7298         "       memcpy(x, w, n); x += n;",
7299         "#endif",
7300         "",
7301         "#ifndef SEPQS",
7302         "       for (i = 0; i < (int) now._nr_qs; i++)",
7303         "               x += col_q(i, x);",
7304         "#endif",
7305
7306         "       x--;",
7307         "       for (i = 0, j = 6; i < nbytelen; i++)",
7308         "       {       if (j == 6)",
7309         "               {       j = 0;",
7310         "                       *(++x) = 0;",
7311         "               } else",
7312         "                       j += 2;",
7313         "               *x |= (nbytes[i] << j);",
7314         "       }",
7315         "       x++;",
7316         "       for (j = 0; j < WS-1; j++)",
7317         "               *x++ = 0;",
7318         "       x -= j; j = 0;",
7319         "       n = ordinal(scratch, x-scratch, 0); /* globals */",
7320         "       *v++ = n&255;",
7321         "       if (n >= (1<< 8)) { *v++ = (n>> 8)&255; j++; }",
7322         "       if (n >= (1<<16)) { *v++ = (n>>16)&255; j++; }",
7323         "       if (n >= (1<<24)) { *v++ = (n>>24)&255; j++; }",
7324         "       *v++ = j;       /* add last count as a byte */",
7325
7326         "       for (i = 0; i < WS-1; i++)",
7327         "               *v++ = 0;",
7328         "       v -= i;",
7329         "#if 0",
7330         "       printf(\"collapse %%d -> %%d\\n\",",
7331         "               vsize, v - (char *)&comp_now);",
7332         "#endif",
7333         "       return v - (char *)&comp_now;",
7334         "}",
7335
7336 "#else",        /* !COLLAPSE */
7337 "#if !defined(NOCOMP)",
7338         "int",
7339         "compress(char *vin, int n)     /* default compression */",
7340         "{",
7341         "#ifdef HC",
7342         "       int delta = 0;",
7343         "       s_hash((uchar *)vin, n); /* sets K1 and K2 */",
7344                 "#ifndef SAFETY",
7345         "       if (S_A)",
7346         "       {       delta++;        /* _a_t  */",
7347                         "#ifndef NOFAIR",
7348         "               if (S_A > NFAIR)",
7349         "                       delta += NFAIR; /* _cnt[] */",
7350                         "#endif",
7351         "       }",
7352                 "#endif",
7353         "       memcpy((char *) &comp_now + delta, (char *) &K1, WS);",
7354         "       delta += WS;",
7355                 "#if HC>0",
7356         "       memcpy((char *) &comp_now + delta, (char *) &K2, HC);",
7357         "       delta += HC;",
7358                 "#endif",
7359         "       return delta;",
7360         "#else",
7361         "       char *vv = vin;",
7362         "       char *v = (char *) &comp_now;",
7363         "       int i;",
7364         "  #ifndef NO_FAST_C", /* disable faster compress */
7365         "       int r = 0, unroll = n/8;", /* most sv are much longer */
7366         "       if (unroll > 0)",
7367         "       {       i = 0;",
7368         "               while (r++ < unroll)",
7369         "               {       /* unroll 8 times, avoid ifs */",
7370         "       /* 1 */         *v = *vv++; v += 1 - Mask[i++];",
7371         "       /* 2 */         *v = *vv++; v += 1 - Mask[i++];",
7372         "       /* 3 */         *v = *vv++; v += 1 - Mask[i++];",
7373         "       /* 4 */         *v = *vv++; v += 1 - Mask[i++];",
7374         "       /* 5 */         *v = *vv++; v += 1 - Mask[i++];",
7375         "       /* 6 */         *v = *vv++; v += 1 - Mask[i++];",
7376         "       /* 7 */         *v = *vv++; v += 1 - Mask[i++];",
7377         "       /* 8 */         *v = *vv++; v += 1 - Mask[i++];",
7378         "               }",
7379         "               r = n - i; /* the rest, at most 7 */",
7380         "               switch (r) {",
7381         "               case 7: *v = *vv++; v += 1 - Mask[i++];",
7382         "               case 6: *v = *vv++; v += 1 - Mask[i++];",
7383         "               case 5: *v = *vv++; v += 1 - Mask[i++];",
7384         "               case 4: *v = *vv++; v += 1 - Mask[i++];",
7385         "               case 3: *v = *vv++; v += 1 - Mask[i++];",
7386         "               case 2: *v = *vv++; v += 1 - Mask[i++];",
7387         "               case 1: *v = *vv++; v += 1 - Mask[i++];",
7388         "               case 0: break;",
7389         "               }",
7390         "               n = i = v - (char *)&comp_now; /* bytes written so far */",
7391         "               r = (n+WS-1)/WS; /* in words, rounded up */",
7392         "               r *= WS;         /* total bytes to fill  */",
7393         "               i = r - i;       /* remaining bytes      */",
7394         "               switch (i) {",   /* fill word */
7395         "               case 7: *v++ = 0;    /* fall thru */",
7396         "               case 6: *v++ = 0;",
7397         "               case 5: *v++ = 0;",
7398         "               case 4: *v++ = 0;",
7399         "               case 3: *v++ = 0;",
7400         "               case 2: *v++ = 0;",
7401         "               case 1: *v++ = 0;",
7402         "               case 0: break;",
7403         "               default: Uerror(\"unexpected wordsize\");",
7404         "               }",
7405         "               v -= i;",
7406         "       } else",
7407         "  #endif",
7408         "       {       for (i = 0; i < n; i++, vv++)",
7409         "                       if (!Mask[i]) *v++ = *vv;",
7410         "               for (i = 0; i < WS-1; i++)",
7411         "                       *v++ = 0;",
7412         "               v -= i;",
7413         "       }",
7414                 "#if 0",
7415         "       printf(\"compress %%d -> %%d\\n\",",
7416         "               n, v - (char *)&comp_now);",
7417                 "#endif",
7418         "       return v - (char *)&comp_now;",
7419         "#endif",
7420         "}",
7421 "#endif",
7422 "#endif",       /* COLLAPSE */
7423         "#if defined(FULLSTACK) && defined(BITSTATE)",
7424 "#if defined(MA)",
7425         "#if !defined(onstack_now)",
7426         "int  onstack_now(void) {}", /* to suppress compiler errors */
7427         "#endif",
7428         "#if !defined(onstack_put)",
7429         "void onstack_put(void) {}", /* for this invalid combination */
7430         "#endif",
7431         "#if !defined(onstack_zap)",
7432         "void onstack_zap(void) {}", /* of directives */
7433         "#endif",
7434 "#else",
7435         "void",
7436         "onstack_zap(void)",
7437         "{      H_el *v, *w, *last = 0;",
7438         "       H_el **tmp = H_tab;",
7439         "       char *nv; int n, m;",
7440         "       static char warned = 0;",
7441         "#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
7442         "       uchar was_last = now._last;",
7443         "       now._last = 0;",
7444         "#endif",
7445         "",
7446         "       H_tab = S_Tab;",
7447         "#ifndef NOCOMP",
7448         "       nv = (char *) &comp_now;",
7449         "       n = compress((char *)&now, vsize);",
7450         "#else",
7451                 "#if defined(BITSTATE) && defined(LC)",
7452         "       nv = (char *) &comp_now;",
7453         "       n = compact_stack((char *)&now, vsize);",
7454                 "#else",
7455         "       nv = (char *) &now;",
7456         "       n = vsize;",
7457                 "#endif",
7458         "#endif",
7459         "#if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
7460         "       s_hash((uchar *)nv, n);",
7461         "#endif",
7462         "       H_tab = tmp;",
7463         "       for (v = S_Tab[j1_spin]; v; Zh++, last=v, v=v->nxt)",
7464         "       {       m = memcmp(&(v->state), nv, n);",
7465         "               if (m == 0)",
7466         "                       goto Found;",
7467         "               if (m < 0)",
7468         "                       break;",
7469         "       }",
7470         "/* NotFound: */",
7471         "#ifndef ZAPH",
7472         "       /* seen this happen, likely harmless in multicore */",
7473         "       if (warned == 0)",
7474         "       {       /* Uerror(\"stack out of wack - zap\"); */",
7475         "               cpu_printf(\"pan: warning, stack incomplete\\n\");",
7476         "               warned = 1;",
7477         "       }",
7478         "#endif",
7479         "       goto done;",
7480         "Found:",
7481         "       ZAPS++;",
7482         "       if (last)",
7483         "               last->nxt = v->nxt;",
7484         "       else",
7485         "               S_Tab[j1_spin] = v->nxt;",
7486         "       v->tagged = (unsigned) n;",
7487         "#if !defined(NOREDUCE) && !defined(SAFETY)",
7488         "       v->proviso = 0;",
7489         "#endif",
7490         "       v->nxt = last = (H_el *) 0;",
7491         "       for (w = Free_list; w; Fa++, last=w, w = w->nxt)",
7492         "       {       if ((int) w->tagged <= n)",
7493         "               {       if (last)",
7494         "                       {       v->nxt = w;",
7495         "                               last->nxt = v;",
7496         "                       } else",
7497         "                       {       v->nxt = Free_list;",
7498         "                               Free_list = v;",
7499         "                       }",
7500         "                       goto done;",
7501         "               }",
7502         "               if (!w->nxt)",
7503         "               {       w->nxt = v;",
7504         "                       goto done;",
7505         "       }       }",
7506         "       Free_list = v;",
7507         "done:",
7508         "#if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
7509         "       now._last = was_last;",
7510         "#endif",
7511         "       return;",
7512         "}",
7513         "",
7514         "#ifndef BFS_PAR",
7515         "       void",
7516         "       onstack_put(void)",
7517         "       {       H_el **tmp = H_tab;",
7518         "       #if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
7519         "               uchar was_last = now._last;",
7520         "               now._last = 0;",
7521         "       #endif",
7522         "               H_tab = S_Tab;",
7523         "               if (h_store((char *)&now, vsize) != 0)",
7524         "       #if defined(BITSTATE) && defined(LC)",
7525         "                       printf(\"pan: warning, double stack entry\\n\");",
7526         "       #else",
7527         "               #ifndef ZAPH",
7528         "                       Uerror(\"cannot happen - unstack_put\");",
7529         "               #endif",
7530         "       #endif",
7531         "               H_tab = tmp;",
7532         "               trpt->ostate = Lstate;",
7533         "               PUT++;",
7534         "       #if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
7535         "               now._last = was_last;",
7536         "       #endif",
7537         "       }",
7538         "       int",
7539         "       onstack_now(void)",
7540         "       {       H_el *tmp;",
7541         "               H_el **tmp2 = H_tab;",
7542         "               char *v; int n, m = 1;\n",
7543         "       #if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
7544         "               uchar was_last = now._last;",
7545         "               now._last = 0;",
7546         "       #endif",
7547         "               H_tab = S_Tab;",
7548         "       #ifdef NOCOMP",
7549         "               #if defined(BITSTATE) && defined(LC)",
7550         "                       v = (char *) &comp_now;",
7551         "                       n = compact_stack((char *)&now, vsize);",
7552         "               #else",
7553         "                       v = (char *) &now;",
7554         "                       n = vsize;",
7555         "               #endif",
7556         "       #else",
7557         "               v = (char *) &comp_now;",
7558         "               n = compress((char *)&now, vsize);",
7559         "       #endif",
7560         "       #if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
7561         "               s_hash((uchar *)v, n);",
7562         "       #endif",
7563         "               H_tab = tmp2;",
7564         "               for (tmp = S_Tab[j1_spin]; tmp; Zn++, tmp = tmp->nxt)",
7565         "               {       m = memcmp(((char *)&(tmp->state)),v,n);",
7566         "                       if (m <= 0)",
7567         "                       {       Lstate = (H_el *) tmp;  /* onstack_now */",
7568         "                               break;",
7569         "               }       }",
7570         "               PROBE++;",
7571         "       #if defined(BCS) && defined(NO_LAST) && defined(HAS_LAST)",
7572         "               now._last = was_last;",
7573         "       #endif",
7574         "               return (m == 0);",
7575         "       }",
7576         "#endif",       /* !BFS_PAR */
7577 "#endif",               /* !MA */
7578         "#endif",       /* FULLSTACK && BITSTATE */
7579
7580         "#ifdef BITSTATE",
7581         "void init_SS(ulong);",
7582         "",
7583         "void",
7584         "sinit(void)",
7585         "{",
7586         "       if (udmem)",
7587         "       {       udmem *= 1024L*1024L;",
7588         "       #if NCORE>1",
7589         "               if (!readtrail)",
7590         "               {       init_SS((ulong) udmem);",
7591         "               } else",
7592         "       #endif",
7593         "       #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
7594         "               SS = (uchar *) sh_pre_malloc((ulong) udmem);",
7595         "       #else",
7596         "               SS = (uchar *) emalloc(udmem);",
7597         "       #endif",
7598         "               b_store = bstore_mod;",
7599         "       } else",
7600         "       {",
7601         "       #if NCORE>1",
7602         "               init_SS(ONE_L<<(ssize-3));",
7603         "       #else",
7604         "               #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
7605         "                       SS = (uchar *) sh_pre_malloc((ulong)(ONE_L<<(ssize-3)));",
7606         "               #else",
7607         "                       SS = (uchar *) emalloc(ONE_L<<(ssize-3));",
7608         "               #endif",
7609         "       #endif",
7610         "       }",
7611         "}",
7612         "#else",
7613         " #if !defined(MA) || defined(COLLAPSE)",
7614         " void",
7615         " set_H_tab(void)",
7616         " {",
7617         "  #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
7618         "       H_tab = (H_el **) sh_pre_malloc((ulong)((ONE_L<<ssize)*sizeof(H_el *)));",
7619         "  #else",
7620         "       H_tab = (H_el **) emalloc((ONE_L<<ssize)*sizeof(H_el *));",
7621         "  #endif",
7622         " }",
7623         " #endif",
7624         "void",
7625         "hinit(void)",
7626         "{",
7627         "       #ifdef MA",
7628         "               #ifdef R_XPT",
7629         "                       {       void r_xpoint(void);",
7630         "                               r_xpoint();",
7631         "                       }",
7632         "               #else",
7633         "                       dfa_init((unsigned short) (MA+a_cycles));",
7634         "                       #if NCORE>1 && !defined(COLLAPSE)",
7635         "                       if (!readtrail)",
7636         "                       {       void init_HT(ulong);",
7637         "                               init_HT(0L);",
7638         "                       }",
7639         "                       #endif",
7640         "               #endif",
7641         "       #endif",
7642         "       #if !defined(MA) || defined(COLLAPSE)",
7643         "               #if NCORE>1 || (defined(BFS_PAR) && defined(USE_TDH) && !defined(WIN32) && !defined(WIN64))",
7644         "                       if (!readtrail)",
7645         "                       {       void init_HT(ulong);",
7646         "                               init_HT((ulong) (ONE_L<<ssize)*sizeof(H_el *));",
7647         "                       #if defined(TRIX) || (defined(BFS_PAR) && defined(COLLAPSE))",
7648         "                               set_H_tab(); /* need both */",
7649         "                       #endif",
7650         "                       } else",
7651         "               #endif",
7652         "                       {       set_H_tab(); /* @htable ssize */",
7653         "                       }",
7654         "       #endif", /* !defined(MA) || defined(COLLAPSE) */
7655         "}",
7656         "#endif\n",
7657
7658         "#if !defined(BITSTATE) || defined(FULLSTACK)",
7659
7660         "#ifdef DEBUG",
7661         "void",
7662         "dumpstate(int wasnew, char *v, int n, int tag)",
7663         "{      int i;",
7664         "#ifndef SAFETY",
7665         "       if (S_A)",
7666         "       {       printf(\"\tstate tags %%d (%%d::%%d): \",",
7667         "                       V_A, wasnew, v[0]);",
7668                 "#ifdef FULLSTACK",
7669         "               printf(\" %%d \", tag);",
7670                 "#endif",
7671         "               printf(\"\\n\");",
7672         "       }",
7673         "#endif",
7674         "#ifdef SDUMP",
7675         "       printf(\"\t State: \");",
7676         "#if !defined(NOCOMP) && !defined(HC)",
7677         "       for (i = 0; i < vsize; i++) printf(\"%%d%%s,\",",
7678         "               ((char *)&now)[i], Mask[i]?\"*\":\"\");",
7679         "#else",
7680         "       for (i = 0; i < vsize; i++)",
7681         "               printf(\"%%d,\", ((char *)&now)[i]);",
7682         "#endif",
7683         "       printf(\"\\n\tVector: \");",
7684         "       for (i = 0; i < n; i++)",
7685         "               printf(\"%%d,\", v[i]);",
7686         "       printf(\"\\n\");",
7687         "#endif",
7688         "}",
7689         "#endif",
7690
7691 "#ifdef MA",
7692         "int",
7693         "g_store(char *vin, int nin, uchar pbit)",
7694         "{      int n, i;",
7695         "       int ret_val = 1;",
7696         "       uchar *v;",
7697         "       static uchar Info[MA+1];",
7698         "#ifndef NOCOMP",
7699         "       n = compress(vin, nin);",
7700         "       v = (uchar *) &comp_now;",
7701         "#else",
7702         "       n = nin;",
7703         "       v = (uchar *) vin;",
7704         "#endif",
7705         "       if (n >= MA)",
7706         "       {       printf(\"pan: error, MA too small, recompile pan.c\");",
7707         "               printf(\" with -DMA=N with N>%%d\\n\", n);",
7708         "               Uerror(\"aborting\");",
7709         "       }",
7710         "       if (n > (int) maxgs)",
7711         "       {       maxgs = (uint) n;",
7712         "       }",
7713         "       for (i = 0; i < n; i++)",
7714         "       {       Info[i] = v[i];",
7715         "       }",
7716         "       for ( ; i < MA-1; i++)",
7717         "       {       Info[i] = 0;",
7718         "       }",
7719         "       Info[MA-1] = pbit;",
7720         "       if (a_cycles)   /* place _a_t at the end */",
7721         "       {       Info[MA] = Info[0];",
7722         "               Info[0]  = 0;",
7723         "       }",
7724         "",
7725         "#ifdef BFS_PAR",
7726         "       e_critical(BFS_STATE);  /* bfs_par / g_store */",
7727         "#endif",
7728         "#if NCORE>1 && !defined(SEP_STATE)",
7729         "       enter_critical(GLOBAL_LOCK); /* crude, but necessary */",
7730         "       /* to make this mode work, also replace emalloc with grab_shared inside store MA routines */",
7731         "#endif",
7732         "",
7733         "       if (!dfa_store(Info))",
7734         "       {       if (pbit == 0",
7735         "               && (now._a_t&1)",
7736         "               &&  depth > A_depth)",
7737         "               {       Info[MA] &= ~(1|16|32); /* _a_t */",
7738         "                       if (dfa_member(MA))",   /* was !dfa_member(MA) */
7739         "                       {       Info[MA-1] = 4; /* off-stack bit */",
7740         "                               nShadow++;",
7741         "                               if (!dfa_member(MA-1))",
7742         "                               {       ret_val = 3;",
7743         "                       #ifdef VERBOSE",
7744         "                                       printf(\"intersected 1st dfs stack\\n\");",
7745         "                       #endif",
7746         "                                       goto done;",
7747         "               }       }       }",
7748         "               ret_val = 0;",
7749         "       #ifdef VERBOSE",
7750         "               printf(\"new state\\n\");",
7751         "       #endif",
7752         "               goto done;",
7753         "       }",
7754         "#ifdef FULLSTACK",
7755         "       if (pbit == 0)",
7756         "       {       Info[MA-1] = 1; /* proviso bit */",
7757         "#ifndef BFS",
7758         "               trpt->proviso = dfa_member(MA-1);",
7759         "#endif",
7760         "               Info[MA-1] = 4; /* off-stack bit */",
7761         "               if (dfa_member(MA-1))",
7762         "               {       ret_val = 1; /* off-stack */",
7763         "       #ifdef VERBOSE",
7764         "                       printf(\"old state\\n\");",
7765         "       #endif",
7766         "               } else",
7767         "               {       ret_val = 2; /* on-stack */",
7768         "       #ifdef VERBOSE",
7769         "                       printf(\"on-stack\\n\");",
7770         "       #endif",
7771         "               }",
7772         "               goto done;",
7773         "       }",
7774         "#endif",
7775         "       ret_val = 1;",
7776         "#ifdef VERBOSE",
7777         "       printf(\"old state\\n\");",
7778         "#endif",
7779         "done:",
7780         "#ifdef BFS_PAR",
7781         "       x_critical(BFS_STATE);",
7782         "#endif",
7783         "#if NCORE>1 && !defined(SEP_STATE)",
7784         "       leave_critical(GLOBAL_LOCK);",
7785         "#endif",
7786         "       return ret_val; /* old state */",
7787         "}",
7788 "#endif",
7789
7790         "#if defined(BITSTATE) && defined(LC)",
7791         "int",
7792         "compact_stack(char *vin, int n)",      /* special case of HC4 */
7793         "{      int delta = 0;",
7794         "       s_hash((uchar *)vin, n); /* sets K1 and K2 */",
7795                 "#ifndef SAFETY",
7796         "       delta++;        /* room for state[0] |= 128 */",
7797                 "#endif",
7798         "       memcpy((char *) &comp_now + delta, (char *) &K1, WS);",
7799         "       delta += WS;",
7800         "       memcpy((char *) &comp_now + delta, (char *) &K2, WS);",
7801         "       delta += WS; /* use all available bits */",
7802         "       return delta;",
7803         "}",
7804         "#endif",
7805
7806         "#ifdef TRIX",
7807         "void",
7808         "sv_populate(void)",
7809         "{      int i, cnt = 0;",
7810         "       TRIX_v6 **base = processes;",
7811         "       int bound = now._nr_pr; /* MAXPROC+1; */",
7812         "#ifdef V_TRIX",
7813         "       printf(\"%%4d: sv_populate\\n\", depth);",
7814         "#endif",
7815         "again:",
7816         "       for (i = 0; i < bound; i++)",
7817         "       {       if (base[i] != NULL)",
7818         "               {       H_el *tmp;",
7819         "                       int m, n; uchar *v;",
7820         "#ifndef BFS",
7821         "                       if (base[i]->modified == 0)",
7822         "                       {       cnt++;",
7823         "       #ifdef V_TRIX",
7824         "                               printf(\"%%4d: %%s %%d not modified\\n\",",
7825         "                               depth, (base == processes)?\"proc\":\"chan\", i);",
7826         "       #endif",
7827         "                               continue;",
7828         "                       }",
7829         "       #ifndef V_MOD",
7830         "                       base[i]->modified = 0;",
7831         "       #endif",
7832         "#endif",
7833         "#ifdef TRIX_RIX",
7834         "                       if (base == processes)",
7835         "                       {       ((P0 *)pptr(i))->_pid = 0;",
7836         "                       }",
7837         "#endif",
7838         "                       n = base[i]->psize;",
7839         "                       v = base[i]->body;",
7840         "                       s_hash(v, n); /* sets j1_spin */",
7841         "                       tmp = H_tab[j1_spin];",
7842         "                       if (!tmp)       /* new */",
7843         "                       {       tmp = grab_state(n);",
7844         "                               H_tab[j1_spin] = tmp;",
7845         "                               m = 1; /* non-zero */",
7846         "                       } else",
7847         "                       {  H_el *ntmp, *olst = (H_el *) 0;",
7848         "                          for (;; hcmp++, olst = tmp, tmp = tmp->nxt)",
7849         "                          {    m = memcmp(((char *)&(tmp->state)), v, n);",
7850         "                               if (m == 0)     /* match */",
7851         "                               {       break;",
7852         "                               } else if (m < 0) /* insert */",
7853         "                               {       ntmp = grab_state(n);",
7854         "                                       ntmp->nxt = tmp;",
7855         "                                       if (!olst)",
7856         "                                               H_tab[j1_spin] = ntmp;",
7857         "                                       else",
7858         "                                               olst->nxt = ntmp;",
7859         "                                       tmp = ntmp;",
7860         "                                       break;",
7861         "                               } else if (!tmp->nxt)   /* append */",
7862         "                               {       tmp->nxt = grab_state(n);",
7863         "                                       tmp = tmp->nxt;",
7864         "                                       break;",
7865         "                       }  }    }",
7866         "                       if (m != 0)",
7867         "                       {       memcpy((char *)&(tmp->state), v, n);",
7868         "#if defined(AUTO_RESIZE) && !defined(BITSTATE)",
7869         "                               tmp->m_K1 = K1; /* set via s_hash */",
7870         "#endif",
7871         "                               if (verbose)",
7872         "                               {       if (base == processes)",
7873         "                                       {       _p_count[i]++;",
7874         "                                       } else",
7875         "                                       {       _c_count[i]++;",
7876         "                       }       }       }",
7877         "                       now._ids_[cnt++] = (char *)&(tmp->state);",
7878         "#ifdef TRIX_RIX",
7879         "                       if (base == processes)",
7880         "                       {       ((P0 *)pptr(i))->_pid = i;",
7881         "                               if (BASE > 0 && i > 0)",
7882         "                               {       ((P0 *)pptr(i))->_pid -= BASE;",
7883         "                       }       }",
7884         "#endif",
7885         "       }       }",
7886 #if 0
7887         if a process appears or disappears: always secure a full sv_populate
7888         (channels come and go only with a process)
7889
7890         only one process can disappear per step
7891         but any nr of channels can be removed at the same time
7892                 if a process disappears, all subsequent entries
7893                 are then in the wrong place in the _ids_ list
7894                 and need to be recomputed
7895         but we do not need to fill out with zeros
7896                 because vsize prevents them being used
7897 #endif
7898         "       /* do the same for all channels */",
7899         "       if (base == processes)",
7900         "       {       base = channels;",
7901         "               bound = now._nr_qs; /* MAXQ+1; */",
7902         "               goto again;",
7903         "       }",
7904         "}",
7905         "#endif\n",
7906         "#if !defined(BFS_PAR) || (!defined(BITSTATE) && !defined(USE_TDH))",
7907         "int",
7908         "h_store(char *vin, int nin)    /* hash table storage */",
7909         "{      H_el *ntmp;",
7910         "       H_el *tmp, *olst = (H_el *) 0;",
7911         "       char *v; int n, m=0;",
7912         " #ifdef HC",
7913         "       uchar rem_a;",
7914         " #endif",
7915         " #ifdef TRIX",
7916         "       sv_populate();  /* update proc and chan ids */",
7917         " #endif",
7918         " #ifdef NOCOMP",       /* defined by BITSTATE */
7919         "       #if defined(BITSTATE) && defined(LC)",
7920         "       if (S_Tab == H_tab)",
7921         "       {       v = (char *) &comp_now;",
7922         "               n = compact_stack(vin, nin);",
7923         "       } else",
7924         "       {       v = vin; n = nin;",
7925         "       }",
7926         "       #else",
7927         "       v = vin; n = nin;",
7928         "       #endif",
7929         " #else",
7930         "       v = (char *) &comp_now;",
7931         "       #ifdef HC",
7932         "       rem_a = now._a_t;",     /* new 5.0 */
7933         "       now._a_t = 0;", /* for hashing/state matching to work right */
7934         "       #endif",
7935         "       n = compress(vin, nin);", /* with HC, this calls s_hash -- but on vin, not on v... */
7936         "       #ifdef HC",
7937         "       now._a_t = rem_a;",     /* new 5.0 */
7938         "       #endif",
7939                 /* with HC4 -a, compress copies K1 and K2 into v[], leaving v[0] free for the a-bit */
7940                 "#ifndef SAFETY",
7941         "       if (S_A)",
7942         "       {       v[0] = 0;       /* _a_t  */",
7943                         "#ifndef NOFAIR",
7944         "               if (S_A > NFAIR)",
7945         "               for (m = 0; m < NFAIR; m++)",
7946         "                       v[m+1] = 0;     /* _cnt[] */",
7947                         "#endif",
7948         "               m = 0;",
7949         "       }",
7950         "       #endif",
7951         " #endif",
7952         " #if !defined(HC) && !(defined(BITSTATE) && defined(LC))",
7953         "       s_hash((uchar *)v, n);",
7954         " #endif",
7955         "       /* for BFS_PAR we can only get here in BITSTATE mode */",
7956         "       /* and in that case we don't use locks */",
7957         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
7958         "       e_critical(BFS_ID);     /* bfs_par / h_store */",
7959         " #endif",
7960         " #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
7961         "       enter_critical(CS_ID);",
7962         " #endif",
7963         "       tmp = H_tab[j1_spin];",
7964         "       if (!tmp)",
7965         "       {  tmp = grab_state(n);", /* no zero-returns with bfs_par */
7966         " #if NCORE>1",
7967         "          if (!tmp)",
7968         "          {    /* if we get here -- we've already issued a warning */",
7969         "               /* but we want to allow the normal distributed termination */",
7970         "               /* to collect the stats on all cpus in the wrapup */",
7971         "       #if !defined(SEP_STATE) && !defined(BITSTATE)",
7972         "               leave_critical(CS_ID);",
7973         "       #endif",
7974         "               return 1; /* allow normal termination */",
7975         "          }",
7976         " #endif",
7977         "          H_tab[j1_spin] = tmp;",
7978         "       } else",
7979         "       {  for (;; hcmp++, olst = tmp, tmp = tmp->nxt)",
7980         "          {   /* skip the _a_t and the _cnt bytes */",
7981         " #ifdef COLLAPSE",
7982         "               if (tmp->ln != 0)",
7983         "               {       if (!tmp->nxt) goto Append;",
7984         "                       continue;",
7985         "               }",
7986         " #endif",
7987         "               m = memcmp(((char *)&(tmp->state)) + S_A, ",
7988         "                       v + S_A, n - S_A);",
7989         "               if (m == 0) {",
7990         " #ifdef SAFETY",
7991                         "#define wasnew 0",
7992         " #else",
7993         "               int wasnew = 0;",
7994         " #endif",
7995
7996         " #if !defined(SAFETY) && !defined(NOCOMP)",
7997         "               if (S_A)",
7998         "               { if ((((char *)&(tmp->state))[0] & V_A) != V_A)",
7999         "                 {     wasnew = 1; nShadow++;",
8000         "                       ((char *)&(tmp->state))[0] |= V_A;",
8001         "                 }",
8002                 "#ifndef NOFAIR",
8003         "                 if (S_A > NFAIR)",
8004         "                 {     /* 0 <= now._cnt[now._a_t&1] < MAXPROC */",
8005         "                       uint ci, bp; /* index, bit pos */",
8006         "                       ci = (now._cnt[now._a_t&1] / 8);",
8007         "                       bp = (now._cnt[now._a_t&1] - 8*ci);",
8008         "                       if (now._a_t&1) /* use tail-bits in _cnt */",
8009         "                       {       ci = (NFAIR - 1) - ci;",
8010         "                               bp = 7 - bp; /* bp = 0..7 */",
8011         "                       }",
8012         "                       ci++;   /* skip over _a_t */",
8013         "                       bp = 1 << bp;   /* the bit mask */",
8014         "                       if ((((char *)&(tmp->state))[ci] & bp)==0)",
8015         "                       {       if (!wasnew)",
8016         "                               {       wasnew = 1;",
8017         "                                       nShadow++;",
8018         "                               }",
8019         "                               ((char *)&(tmp->state))[ci] |= bp;",
8020         "                       }",
8021         "                  }",
8022         "                  /* else: wasnew == 0, i.e., old state */",
8023                 "#endif",
8024         "               }",
8025         " #endif",
8026
8027         " #if NCORE>1",
8028         "               Lstate = (H_el *) tmp;  /* h_store */",
8029         " #endif",
8030
8031         "#ifdef FULLSTACK",
8032                 "#ifndef SAFETY",       /* or else wasnew == 0 */
8033         "               if (wasnew)",
8034         "               {       Lstate = (H_el *) tmp;  /* h_store */",
8035         "                       tmp->tagged |= V_A;",
8036         "                       if ((now._a_t&1)",
8037         "                       && (tmp->tagged&A_V)",
8038         "                       && depth > A_depth)",
8039         "                       {",
8040         "intersect:",
8041                 "#ifdef CHECK",
8042         " #if NCORE>1",
8043         "       printf(\"cpu%%d: \", core_id);",
8044         " #endif",
8045         "       printf(\"1st dfs-stack intersected on state %%d+\\n\",",
8046         "               (int) tmp->st_id);",
8047                 "#endif",
8048
8049         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8050         "                               x_critical(BFS_ID);",
8051         " #endif",
8052         " #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8053         "                               leave_critical(CS_ID);",
8054         " #endif",
8055
8056         "                               return 3;",
8057         "                       }",
8058                 "#ifdef CHECK",
8059         " #if NCORE>1",
8060         "       printf(\"cpu%%d: \", core_id);",
8061         " #endif",
8062         "       printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
8063                 "#endif",
8064                 "#ifdef DEBUG",
8065         "       dumpstate(1, (char *)&(tmp->state),n,tmp->tagged);",
8066                 "#endif",
8067         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8068         "                       x_critical(BFS_ID);",
8069         " #endif",
8070         " #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8071         "                       leave_critical(CS_ID);",
8072         " #endif",
8073         "                       return 0;",
8074         "               } else",
8075                 "#endif",
8076         "               if ((S_A)?(tmp->tagged&V_A):tmp->tagged)",
8077         "               {       Lstate = (H_el *) tmp;  /* h_store */",
8078                 "#ifndef SAFETY",
8079         "                       /* already on current dfs stack */",
8080         "                       /* but may also be on 1st dfs stack */",
8081         "                       if ((now._a_t&1)",
8082         "                       && (tmp->tagged&A_V)",
8083
8084         "                       && depth > A_depth",
8085                 /* new (Zhang's example) */
8086                 "#ifndef NOFAIR",
8087         "                       && (!fairness || now._cnt[1] <= 1)",
8088                 "#endif",
8089         "                       )",
8090
8091         "                               goto intersect;",
8092                 "#endif",
8093                 "#ifdef CHECK",
8094         " #if NCORE>1",
8095         "       printf(\"cpu%%d: \", core_id);",
8096         " #endif",
8097         "       printf(\"\tStack state %%d\\n\", (int) tmp->st_id);",
8098                 "#endif",
8099                 "#ifdef DEBUG",
8100         "       dumpstate(0, (char *)&(tmp->state),n,tmp->tagged);",
8101                 "#endif",
8102         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8103         "                       x_critical(BFS_ID);",
8104         " #endif",
8105         " #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8106         "                       leave_critical(CS_ID);",
8107         " #endif",
8108         "                       return 2; /* match on stack */",
8109         "               }",
8110         "#else",
8111         "               if (wasnew)",
8112         "               {",
8113                 "#ifdef CHECK",
8114         " #if NCORE>1",
8115         "       printf(\"cpu%%d: \", core_id);",
8116         " #endif",
8117         "       printf(\"\tNew state %%d+\\n\", (int) tmp->st_id);",
8118                 "#endif",
8119                 "#ifdef DEBUG",
8120         "       dumpstate(1, (char *)&(tmp->state), n, 0);",
8121                 "#endif",
8122         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8123         "                       x_critical(BFS_ID);",
8124         " #endif",
8125         " #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8126         "                       leave_critical(CS_ID);",
8127         " #endif",
8128         "                       return 0;",
8129         "               }",
8130         "#endif",
8131                 "#ifdef CHECK",
8132         "#if NCORE>1",
8133         "       printf(\"cpu%%d: \", core_id);",
8134         "#endif",
8135         "       printf(\"\tOld state %%d\\n\", (int) tmp->st_id);",
8136                 "#endif",
8137                 "#ifdef DEBUG",
8138         "       dumpstate(0, (char *)&(tmp->state), n, 0);",
8139                 "#endif",
8140         "#if defined(BCS)",
8141         "  #ifdef CONSERVATIVE",
8142         "       if (tmp->ctx_low > trpt->sched_limit)",
8143         "       {       tmp->ctx_low = trpt->sched_limit;",
8144         "               tmp->ctx_pid[(now._last)/8] = 1 << ((now._last)%%8); /* new */",
8145         "       #ifdef CHECK",
8146         "               #if NCORE>1",
8147         "               printf(\"cpu%%d: \", core_id);",
8148         "               #endif",
8149         "               printf(\"\t\tRevisit with fewer context switches\\n\");",
8150         "       #endif",
8151         "               nstates--;",
8152         "               #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8153         "               x_critical(BFS_ID);",
8154         "               #endif",
8155         "               #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8156         "               leave_critical(CS_ID);",
8157         "               #endif",
8158         "               return 0;",
8159         "       } else if ((tmp->ctx_low == trpt->sched_limit",
8160         "       &&   (tmp->ctx_pid[(now._last)/8] & ( 1 << ((now._last)%%8) )) == 0 ))",
8161         "       {       tmp->ctx_pid[(now._last)/8] |= 1 << ((now._last)%%8); /* add */",
8162         "       #ifdef CHECK",
8163         "               #if NCORE>1",
8164         "               printf(\"cpu%%d: \", core_id);",
8165         "               #endif",
8166         "               printf(\"\t\tRevisit with same nr of context switches\\n\");",
8167         "       #endif",
8168         "               nstates--;",
8169         "               #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8170         "               x_critical(BFS_ID);",
8171         "               #endif",
8172         "               #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8173         "               leave_critical(CS_ID);",
8174         "               #endif",
8175         "               return 0;",
8176         "       }",
8177         "  #endif",
8178         "#endif",
8179         " #ifdef REACH",
8180         "       if (tmp->D > depth)",
8181         "       {       tmp->D = depth;",
8182         "       #ifdef CHECK",
8183         "               #if NCORE>1",
8184         "               printf(\"cpu%%d: \", core_id);",
8185         "               #endif",
8186         "               printf(\"\t\tReVisiting (from smaller depth)\\n\");",
8187         "       #endif",
8188         "               nstates--;",
8189         "       #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8190         "               x_critical(BFS_ID);",
8191         "       #endif",
8192         "       #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8193         "               leave_critical(CS_ID);",
8194         "       #endif",
8195 #if 0
8196   a possible variation of iterative search for shortest counter-example
8197   (pan -i and pan -I) suggested by Pierre Moro (for safety properties):
8198   state revisits on shorter depths do not start until after
8199   the first counter-example is found.  this assumes that the max search
8200   depth is set large enough that a first (possibly long) counter-example
8201   can be found
8202   if set too short, this variant can miss the counter-example, even if
8203   it would otherwise be shorter than the depth-limit.
8204   (p.m. unsure if this preserves the guarantee of finding the
8205    shortest counter-example - so not enabled by default)
8206         "               if (errors > 0 && iterative)", /* Moro */
8207 #endif
8208         "               return 0;",
8209         "       }",
8210         " #endif",
8211         " #if (defined(BFS) && defined(Q_PROVISO)) || NCORE>1",
8212         "               Lstate = (H_el *) tmp;  /* h_store */",
8213         " #endif",
8214         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8215         "               x_critical(BFS_ID);",
8216         " #endif",
8217         " #if NCORE>1 && !defined(SEP_STATE) && !defined(BITSTATE)",
8218         "               leave_critical(CS_ID);",
8219         " #endif",
8220         "               return 1; /* match outside stack */",
8221         "              } else if (m < 0)",
8222         "              {        /* insert state before tmp */",
8223         "                       ntmp = grab_state(n);",
8224         " #if NCORE>1",
8225         "                       if (!ntmp)",
8226         "                       {",
8227         "       #if !defined(SEP_STATE) && !defined(BITSTATE)",
8228         "                               leave_critical(CS_ID);",
8229         "       #endif",
8230         "                               return 1;  /* allow normal termination */",
8231         "                       }",
8232         " #endif",
8233         "                       ntmp->nxt = tmp;",
8234         "                       if (!olst)",
8235         "                               H_tab[j1_spin] = ntmp;",
8236         "                       else",
8237         "                               olst->nxt = ntmp;",
8238         "                       tmp = ntmp;",
8239         "                       break;",
8240         "              } else if (!tmp->nxt)",
8241         "              {        /* append after tmp */",
8242         " #ifdef COLLAPSE",
8243         "Append:",
8244         " #endif",
8245         "                       tmp->nxt = grab_state(n);",
8246         " #if NCORE>1",
8247         "                       if (!tmp->nxt)",
8248         "                       {",
8249         "       #if !defined(SEP_STATE) && !defined(BITSTATE)",
8250         "                               leave_critical(CS_ID);",
8251         "       #endif",
8252         "                               return 1;  /* allow normal termination */",
8253         "                       }",
8254         " #endif",
8255         "                       tmp = tmp->nxt;",
8256         "                       break;",
8257         "          }   }",
8258         "       }",
8259         " #ifdef CHECK",
8260         "       tmp->st_id = (unsigned) nstates;",
8261         " #if NCORE>1",
8262         "       printf(\"cpu%%d: \", core_id);",
8263         " #endif",
8264                 "#ifdef BITSTATE",
8265         "       printf(\"       Push state %%d\\n\", ((int) nstates) - 1);",
8266                 "#else",
8267         "       printf(\"       New state %%d\\n\", (int) nstates);",
8268                 "#endif",
8269         "#endif",
8270         " #if defined(BCS)",
8271         "       tmp->ctx_low = trpt->sched_limit;",
8272         "       #ifdef CONSERVATIVE",
8273         "       tmp->ctx_pid[(now._last)/8] = 1 << ((now._last)%%8); /* new limit */",
8274         "       #endif",
8275         " #endif",
8276         " #if !defined(SAFETY) || defined(REACH)",
8277         "       tmp->D = depth;",
8278         " #endif",
8279         " #if !defined(SAFETY) && !defined(NOCOMP)",
8280         "       if (S_A)",
8281         "       {       v[0] = V_A;",
8282                 "#ifndef NOFAIR",
8283         "               if (S_A > NFAIR)",
8284         "               {       uint ci, bp; /* as above */",
8285         "                       ci = (now._cnt[now._a_t&1] / 8);",
8286         "                       bp = (now._cnt[now._a_t&1] - 8*ci);",
8287         "                       if (now._a_t&1)",
8288         "                       {       ci = (NFAIR - 1) - ci;",
8289         "                               bp = 7 - bp; /* bp = 0..7 */",
8290         "                       }",
8291         "                       v[1+ci] = 1 << bp;",
8292         "               }",
8293                 "#endif",
8294         "       }",
8295         " #endif",
8296         " #if defined(AUTO_RESIZE) && !defined(BITSTATE)",
8297         "       tmp->m_K1 = K1;",
8298         " #endif",
8299         "       memcpy(((char *)&(tmp->state)), v, n);",
8300         " #ifdef FULLSTACK",
8301         "       tmp->tagged = (S_A)?V_A:(depth+1);",
8302                 "#ifdef DEBUG",
8303         "               dumpstate(-1, v, n, tmp->tagged);",
8304                 "#endif",
8305         "       Lstate = (H_el *) tmp;  /* end of h_store */",
8306         " #else",
8307         "       #ifdef DEBUG",
8308         "               dumpstate(-1, v, n, 0);",
8309         "       #endif",
8310         "       #if NCORE>1",
8311         "               Lstate = (H_el *) tmp;  /* end of h_store */",
8312         "       #endif",
8313         " #endif",
8314
8315         " #if defined(BFS_PAR) && !defined(BFS_SEP_HASH)",
8316         "               x_critical(BFS_ID);",
8317         " #endif",
8318         " #if NCORE>1",
8319         "       #ifdef V_PROVISO",
8320         "               tmp->cpu_id = core_id;",
8321         "       #endif",
8322         "       #if !defined(SEP_STATE) && !defined(BITSTATE)",
8323         "               leave_critical(CS_ID);",
8324         "       #endif",
8325         " #endif",
8326
8327         "       return 0;",
8328         "}",    /* end of h_store */
8329         "#endif", /* !BFS_PAR || !USE_TDH */
8330         "",
8331         "void",
8332         "o_hash32(uchar *s, int len, int h) /* 32-bit, like d_sfh, but with seed */",
8333         "{       uint32_t tmp;",
8334         "        int rem;",
8335         "",
8336         "        rem = len & 3;",
8337         "        len >>= 2;",
8338         "",
8339         "        for ( ; len > 0; len--)",
8340         "        {       h  += get16bits(s);",
8341         "                tmp = (get16bits(s+2) << 11) ^ h;",
8342         "                h   = (h << 16) ^ tmp;",
8343         "                s  += 2*sizeof(uint16_t);",
8344         "                h  += h >> 11;",
8345         "        }",
8346         "        switch (rem) {",
8347         "        case 3: h += get16bits(s);",
8348         "                h ^= h << 16;",
8349         "                h ^= s[sizeof(uint16_t)] << 18;",
8350         "                h += h >> 11;",
8351         "                break;",
8352         "        case 2: h += get16bits(s);",
8353         "                h ^= h << 11;",
8354         "                h += h >> 17;",
8355         "                break;",
8356         "        case 1: h += *s;",
8357         "                h ^= h << 10;",
8358         "                h += h >> 1;",
8359         "                break;",
8360         "        }",
8361         "        h ^= h << 3;",
8362         "        h += h >> 5;",
8363         "        h ^= h << 4;",
8364         "        h += h >> 17;",
8365         "        h ^= h << 25;",
8366         "        h += h >> 6;",
8367         "",
8368         "        K1 = h;",
8369         "}",
8370         "void",
8371         "o_hash64(uchar *kb, int nbytes, int seed)", /* 64-bit hash */
8372         "{      uint8_t  *bp;",
8373         "       uint64_t a, b, c, n;",
8374         "       const uint64_t *k = (uint64_t *) kb;",
8375         "       n = nbytes/WS;  /* nr of 8-byte chunks */",
8376         "       /* extend to multiple of words, if needed */",
8377         "       a = WS - (nbytes %% WS);",
8378         "       if (a > 0 && a < WS)",
8379         "       {       n++;",
8380         "               bp = kb + nbytes;",
8381         "               switch (a) {",
8382         "               case 7: *bp++ = 0; /* fall thru */",
8383         "               case 6: *bp++ = 0; /* fall thru */",
8384         "               case 5: *bp++ = 0; /* fall thru */",
8385         "               case 4: *bp++ = 0; /* fall thru */",
8386         "               case 3: *bp++ = 0; /* fall thru */",
8387         "               case 2: *bp++ = 0; /* fall thru */",
8388         "               case 1: *bp   = 0;",
8389         "               case 0: break;",
8390         "       }       }",
8391         "       a = (uint64_t) seed;",
8392         "       b = HASH_CONST[HASH_NR];",
8393         "       c = 0x9e3779b97f4a7c13LL; /* arbitrary */",
8394         "       while (n >= 3)",
8395         "       {       a += k[0];",
8396         "               b += k[1];",
8397         "               c += k[2];",
8398         "               mix(a,b,c);",
8399         "               n -= 3;",
8400         "               k += 3;",
8401         "       }",
8402         "       c += (((uint64_t) nbytes)<<3);",
8403         "       switch (n) {",
8404         "       case 2: b += k[1];",
8405         "       case 1: a += k[0];",
8406         "       case 0: break;",
8407         "       }",
8408         "       mix(a,b,c);",
8409         "",
8410         "       K1 = a;",
8411         "}",
8412         "",
8413         "#if defined(USE_TDH) && !defined(WIN32) && !defined(WIN64)",
8414 #if 0
8415         some problems with this storage mode:
8416
8417         0. pre-allocates full hash-table with slots equal to max statevector size
8418             e.g. with -w26 we allocate 2^26 (64 M) slots of VECTORSZ large
8419            which can accomodate up to 64 M states
8420            once you get close to or exceed the max, the search aborts
8421            with a 'hashtable full' message
8422            in HC mode the max storage needed per state is more modest and independent
8423            of the maximum vectorsize; which makes this mode attractive as a default
8424
8425         1. does not support PO reduction through the Lstate->ostate->tagged
8426            to distinguish open from closed states - this can reduce states by 50%
8427            could add this as another bit from the hash value
8428            e.g., could add it in HC mode to the first hash?
8429
8430         2. the same state may be stored multiple times
8431 #endif
8432         "#ifdef HC",
8433         "       #ifndef T_HC",
8434         "               #ifdef BFS_HC",
8435         "                       #define T_HC    BFS_HC",
8436         "               #else",
8437         "                       #define T_HC    2",
8438         "               #endif",
8439         "       #endif",
8440         "       #if T_HC<1 || T_HC>4",
8441         "               #error \"BFS_HC must be 1, 2, 3, or 4 (default is 2)\"",
8442         "       #endif",
8443         "#endif",
8444         "",
8445         "#define T_ROW           6", /* related to cache line size */
8446         "#define T_ROW_SIZE      (1<<T_ROW)",
8447         "#define T_ROW_MASK     -(1<<T_ROW)",
8448         "#define T_FREE          0",
8449         "#define T_STAT          1      /* status bit */",
8450         "#ifndef T_VSZ",
8451         "       #define T_VSZ   VECTORSZ/4      /* compressed vectorsize */",
8452         "#endif",
8453         "",
8454         "static volatile char     *ohash_sd;    /* state data  */",
8455         "static volatile uint32_t *ohash_hv;    /* hash values */",
8456         "static ulong              ohash_max;",
8457         "static ulong              ohash_mask;",
8458         "",
8459         "#if defined(USE_TDH) && defined(Q_PROVISO)",
8460         "  static volatile uchar    *ohash_inq; /* open/closed flag BFS_INQ */",
8461         "#endif",
8462         "#ifdef HC",
8463         "  static uint32_t         ohash_hc[T_HC];",
8464         "  static ulong            ohash_hc_sz;",
8465         "#endif",
8466         "",
8467         "void",
8468         "init_HT(ulong x)               /* USE_TDH cygwin/linux */",
8469         "{      x = x / (ulong) sizeof(H_el *); /* room for x pointers */",
8470         "       #ifdef DEBUG",
8471         "       printf(\"prealloc x %%lu v %%d  x*v %%lu\\n\",",
8472         "               x, T_VSZ, (ulong) (x * (ulong)T_VSZ));",
8473         "       #endif",
8474         "#ifndef HC",
8475         "       if (!(x * (ulong) T_VSZ > x))",
8476         "       {       Uerror(\"assertion x * (ulong) T_VSZ > x fails\");",
8477         "       }",
8478         "       #ifdef BFS_SEP_HASH",
8479         "               ohash_sd   = (char *) emalloc(x * (ulong) T_VSZ);",
8480         "       #else",
8481         "               ohash_sd   = (volatile char *) sh_pre_malloc(x * (ulong) T_VSZ);",
8482         "       #endif",
8483         "#else", /* assume T_HC >= 1, and normally 2 */
8484         "       ohash_hc_sz = (ulong) (T_HC * (ulong) sizeof(uint32_t));",
8485         "       if (!(x * ohash_hc_sz > x))",   /* watch for overflow */
8486         "       {       Uerror(\"assertion x * ohash_hc_sz > x fails\");",
8487         "       }",
8488         "       #ifdef BFS_SEP_HASH",
8489         "               ohash_sd   = (char *) emalloc(x * ohash_hc_sz);",
8490         "       #else",
8491         "               ohash_sd   = (volatile char *) sh_pre_malloc(x * ohash_hc_sz);",
8492         "       #endif",
8493         "#endif",
8494         "#ifdef BFS_SEP_HASH",
8495         "       ohash_hv = (uint32_t *) emalloc(x * (ulong) sizeof(uint32_t));",
8496         "#else",
8497         "       ohash_hv = (volatile uint32_t *) sh_pre_malloc(x * (ulong) sizeof(uint32_t));",
8498         "#endif",
8499         "       ohash_mask = (((ulong)1)<<ssize)-1;",
8500         "       ohash_max  = (((ulong)1)<<ssize)/100;",
8501         "#if defined(USE_TDH) && defined(Q_PROVISO)",
8502         "       #ifdef BFS_SEP_HASH",
8503         "       ohash_inq  = (uchar *) emalloc(x * (ulong) sizeof(uchar));",
8504         "       #else",
8505         "       ohash_inq  = (volatile uchar *) sh_pre_malloc(x * (ulong) sizeof(uchar));",
8506         "       #endif",
8507         "#endif",
8508         "}",
8509         "",
8510         "static int h_table_full;",
8511         "#ifdef L_BOUND",
8512         "void",
8513         "bfs_mark_live(void)",
8514         "{      int i;",
8515         "",
8516         "       trpt->o_pm &= ~2;",
8517         "#ifdef VERBOSE",
8518         "       bfs_printf(\"check to mark\\n\");",
8519         "#endif",
8520         "       for (i = 0; i < (int) now._nr_pr; i++)",
8521         "       {       P0 *ptr = (P0 *) pptr(i);",
8522         "               if (accpstate[ptr->_t][ptr->_p])",
8523         "               {       trpt->o_pm |= 2;",
8524         "                       now._l_bnd = L_bound;",
8525         "                       now._l_sds = (uchar *) 0;",
8526         "#ifdef VERBOSE",
8527         "                       bfs_printf(\"mark state live\\n\");",
8528         "#endif",
8529         "                       break;",
8530         "       }       }",
8531         "}",
8532         "void",
8533         "bfs_check_live(uchar b, uchar *s)",
8534         "{      /* assert(b>0); */",
8535         "       now._l_bnd = b-1;       /* decrease bound */",
8536         "#ifdef VERBOSE",
8537         "       bfs_printf(\"check live %%d\\n\", b);",
8538         "#endif",
8539         "       if (b == L_bound && boq == -1)", /* never mid rv */
8540         "       {       now._l_sds = (uchar *) Lstate;  /* new target */",
8541         "       } else",
8542         "       {       now._l_sds = s;         /* restore target */",
8543         "               if (s == (uchar *) Lstate)",
8544         "               {       depthfound = depth - (BASE+1)*(L_bound - now._l_bnd - 1);",
8545         "                       uerror(\"accept cycle found\");",
8546         "                       depthfound = -1;",
8547         "                       now._l_bnd = 0;",
8548         "                       now._l_sds = (uchar *) 0;",
8549         "       }       }",
8550         "#ifdef VERBOSE",
8551         "       bfs_printf(\"set l_bound to %%d -- sds %%p\\n\", b-1, (void *) now._l_sds);",
8552         "#endif",
8553         "}",
8554         "#endif",
8555         "/* closed hashing with locality - similar to ltsmin */",
8556         "int",
8557         "o_store(const char *vin, int nin)",
8558         "{      int i, seed = 0;",
8559         "       ulong hash_v, ix, ex;",
8560         "       uint32_t T_BUSY, T_DONE;",
8561         "       volatile uint32_t *t_entry;",
8562         "#ifdef HC",
8563         "       ulong vs = ohash_hc_sz;",
8564         "#else",
8565         "       ulong vs = (ulong) T_VSZ;",
8566         "#endif",
8567         "#ifdef L_BOUND",
8568         "       uchar o_bnd, *o_sds;",
8569         "#endif",
8570         "#ifndef STOP_ON_FULL",
8571         "       if (h_table_full)",
8572         "       {       goto done;",
8573         "       }",
8574         "#endif",
8575         "#ifdef L_BOUND",
8576         "       if (now._l_bnd == 0)",
8577         "       {       bfs_mark_live();",
8578         "       }",
8579         "       #ifdef VERBOSE",
8580         "         else",
8581         "       {       bfs_printf(\"non-markable state %%d\\n\", now._l_bnd);",
8582         "       }",
8583         "       #endif",
8584         "       o_bnd = now._l_bnd;",
8585         "       o_sds = now._l_sds;",
8586         "       now._l_bnd = (o_bnd)?1:0;  /* mark nested phase of bounded search */",
8587         "       now._l_sds = (uchar *) 0;",
8588         "#endif",
8589         "#if !defined(HC) && !defined(T_NOCOMP)",
8590         "       nin = compress((char *)vin, nin);",
8591         "       vin = (char *) &comp_now;",
8592         "#endif",
8593         "       do {    o_hash((uchar *)vin, nin, seed++);",
8594         "               hash_v = K1;",
8595         "       } while (hash_v == T_FREE || hash_v == T_STAT); /* unlikely, hash_v 0 or 1 */",
8596         "",
8597         "       T_BUSY = ((uint32_t) hash_v & ~((uint32_t) T_STAT));    /* hash with status bit 0 */",
8598         "       T_DONE = ((uint32_t) hash_v |  ((uint32_t) T_STAT));    /* hash with status bit 1 */",
8599         "#ifdef HC",
8600         "       d_hash((uchar *)vin, nin);",                    /* HC */
8601         "       ohash_hc[0] = (uint32_t) K1;",
8602         "       #if T_HC>1",
8603         "       ohash_hc[1] = (uint32_t) (K1>>32);",            /* assumes ulong = 64 bits */
8604         "       #endif",
8605         "       #if T_HC>2",
8606         "       ohash_hc[2] = (uint32_t) K2;",
8607         "       #endif",
8608         "       #if T_HC>3",
8609         "       ohash_hc[3] = (uint32_t) (K2>>32);",
8610         "       #endif",
8611         "#endif",
8612         "       while (seed < ohash_max)",
8613         "       {       ix = hash_v & ohash_mask;",
8614         "               ex = (ix & T_ROW_MASK) + T_ROW_SIZE;",
8615         "               for (i = 0; i < T_ROW_SIZE; i++)",
8616         "               {       t_entry = (uint32_t *) &ohash_hv[ix];",
8617         "                       if (*t_entry == T_FREE && cas(t_entry, T_FREE, T_BUSY))",
8618         "                       {",
8619         "#ifndef HC",
8620         "                               memcpy((char *) &ohash_sd[ix * vs], vin, nin);",
8621         "#else",
8622         "                               memcpy((char *) &ohash_sd[ix * vs], (char *) ohash_hc, vs);",
8623         "#endif",
8624         "#if defined(USE_TDH) && defined(Q_PROVISO)",
8625         "                               ohash_inq[ix] = (uchar) BFS_INQ;",
8626         "                               Lstate = (H_el *) &ohash_inq[ix];",
8627         "#endif",
8628         "                               *t_entry = T_DONE;",
8629         "#ifdef VERBOSE",
8630         "       #ifdef L_BOUND",
8631         "                               bfs_printf(\"New state %%p [%%p]\\n\",",
8632         "                                       (void *) Lstate, (void *) o_sds);",
8633         "       #else",
8634         "                               bfs_printf(\"New state %%p\\n\", (void *) Lstate);",
8635         "       #endif",
8636         "#endif",
8637         "#ifdef L_BOUND",
8638         "                               if (o_bnd) { bfs_check_live(o_bnd, o_sds); }",
8639         "#endif",
8640         "                               return 0;       /* New State */",
8641         "                       }",
8642         "                       while (*t_entry == T_BUSY)",
8643         "                       {       usleep(2);      /* wait */",
8644         "                       }",
8645         "                       if (*t_entry == T_DONE /* (first) hash matches, check data */",
8646         "#ifndef HC",
8647         "                       &&   memcmp((char *) &ohash_sd[ix * vs], vin, nin) == 0)",
8648         "#else",
8649         "                       &&   memcmp((char *) &ohash_sd[ix * vs], (char *) ohash_hc, vs) == 0)",
8650         "#endif",
8651         "                       {",
8652         "#if defined(USE_TDH) && defined(Q_PROVISO)",
8653         "                               Lstate = (H_el *) &ohash_inq[ix];",
8654         "#endif",
8655         "#ifdef VERBOSE",
8656         "       #ifdef L_BOUND",
8657         "                               bfs_printf(\"Old state %%p [%%p]\\n\",",
8658         "                                       (void *) Lstate, (void *) o_sds);",
8659         "       #else",
8660         "                               bfs_printf(\"Old state %%p\\n\", (void *) Lstate);",
8661         "       #endif",
8662         "#endif",
8663         "#ifdef L_BOUND",
8664         "                               if (o_bnd) { bfs_check_live(o_bnd, o_sds); }",
8665         "#endif",
8666         "                               return 1;       /* Old State */",
8667         "                       }",
8668         "                       hcmp++; ix++;",
8669         "                       ix = (ix==ex) ? ex - T_ROW_SIZE : ix;",
8670         "               }",
8671         "               /* find a new slot: */",
8672         "               do {    o_hash((uchar *)vin, nin, (int) (hash_v + seed++));",
8673         "                       hash_v = K1;",
8674         "               } while (hash_v == T_FREE || hash_v == T_STAT);",
8675         "               T_BUSY = ((uint32_t) hash_v & ~((uint32_t) T_STAT));",
8676         "               T_DONE = ((uint32_t) hash_v |  ((uint32_t) T_STAT));",
8677         "       }",
8678         "#ifdef STOP_ON_FULL",
8679         "       Uerror(\"hash table full\");",
8680         "       /* no return from Uerror */",
8681         "#else",
8682         "       if (!h_table_full)",
8683         "       {       h_table_full++;",
8684         "               if (who_am_i == 0)",
8685         "               {       bfs_printf(\"hash table is full\\n\");",
8686         "       }       }",
8687         "done:",
8688         "       bfs_punt++;     /* counts this as a lost state */",
8689         "#endif",
8690         "#ifdef L_BOUND",
8691         "       now._l_bnd = 0; /* no more checking */",
8692         "       now._l_sds = (uchar *) 0;",
8693         "#endif",
8694         "       return 1; /* technically should be 0, but we want to throttle down */",
8695         "}",
8696         "#endif", /* USE_TDH && !WIN32 && !WIN64 */
8697         "#endif", /* !BITSTATE || FULLSTACK */
8698         "#include TRANSITIONS",
8699         0,
8700 };