# include "lbc.hh"

value     v[2];
gate_list gts;
var_list  vrs;
int       i;

frame M;

PUBLIC void
c0 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    b = mkhd (b, 1);
    gts = b->fth->gte;
    gts[1] = TRUE;
    gts[2] = TRUE;
    M = b->frm;

    b = mkhd (b, 2);
    gts = b->fth->gte;
    gts[3] = TRUE;
    gts[4] = TRUE;
    M = b->frm;

    mkpe (b, 3, 4);
    gts = b->gte;
    gts[3] = TRUE;
    gts[4] = TRUE;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 3: {
    M->ent = 0;
    M->but = 1;
    c1 (b);
    break;
  }
  case 4: {
    push_gte (3);
    push_gte (4);
    b = mkre (b, 2);
    M->ent = 0;
    M->but = 3;
    c3 (b);
    break;
  }
  }
}

PUBLIC void
c1 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkpe (b, 1, 2);
    gts = b->gte;
    c1 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 1: {
    v[0] = (udatum)n1 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  case 2: {
    mkpe (b, 3, 4);
    gts = b->gte;
    c1 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 3: {
    v[0] = (udatum)n2 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  case 4: {
    mkpe (b, 5, 6);
    gts = b->gte;
    c1 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 5: {
    v[0] = (udatum)n3 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  case 6: {
    v[0] = (udatum)n4 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  }
}

PUBLIC void
c2 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 1, 1, 1, 1, -1, 0);
    break;
  }
  case 1: {
    mkso ((udatum)left ());
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 2, 3, 2, 0, -1, 0);
    break;
  }
  case 2: {
    mkdl (b, 3, 1);
    break;
  }
  case 3: {
    mkso ((udatum)right ());
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 4, 3, 2, 0, -1, 0);
    break;
  }
  case 4: {
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 5, 2, 1, 1, -1, 0);
    break;
  }
  case 5: {
    mkso ((udatum)left ());
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 6, 4, 2, 0, -1, 0);
    break;
  }
  case 6: {
    mkso ((udatum)right ());
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 7, 4, 2, 0, -1, 0);
    break;
  }
  case 7: {
    mki (b, 8, 0);
    break;
  }
  case 8: {
    v[0] = ud_copy (2, M->rav[0]);
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    goto again;
  }
  }
}

PUBLIC void
c3 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkpe (b, 1, 2);
    gts = b->gte;
    c3 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 1: {
    v[0] = (udatum)n1 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 4;
    c4 (b);
    break;
  }
  case 2: {
    mkpe (b, 3, 4);
    gts = b->gte;
    c3 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 3: {
    v[0] = (udatum)n2 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 4;
    c4 (b);
    break;
  }
  case 4: {
    mkpe (b, 5, 6);
    gts = b->gte;
    c3 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 5: {
    v[0] = (udatum)n3 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 4;
    c4 (b);
    break;
  }
  case 6: {
    v[0] = (udatum)n4 ();
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 4;
    c4 (b);
    break;
  }
  }
}

PUBLIC void
c4 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    b = mken (b, 1, 8, 0);
    vrs = b->fth->rav;
    goto again;
  }
  case 1: {
    mkch (b, 2, 5);
    c4 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 2: {
    mkso ((udatum)left ());
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 3, 1, 2, 0, -1, 0);
    break;
  }
  case 3: {
    mkso ((udatum)left ());
    mkso (ud_copy (2, M->rav[0]));
    mkad (b, 4, 2, 2, 0, -1, 0);
    break;
  }
  case 4: {
    mkex (b, 0, 2, 0);
    break;
  }
  case 5: {
    mkso ((udatum)right ());
    mkso ((udatum)plus (kd_copy ((kdatum)M->rav[0]), n1 ()));
    mkad (b, 6, 1, 2, 0, -1, 0);
    break;
  }
  case 6: {
    mkso ((udatum)right ());
    mkso ((udatum)plus (kd_copy ((kdatum)M->rav[0]), n1 ()));
    mkad (b, 7, 2, 2, 0, -1, 0);
    break;
  }
  case 7: {
    mkex (b, 0, 2, 0);
    break;
  }
  case 8: {
    v[0] = ud_copy (2, M->rav[0]);
    if (M->rav[0] != NULL) {
      ud_free (2, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    goto again;
  }
  }
}


char*  TSprocesses[]= {""};

char** TSgates[]= {TSprocesses};

char** TSvariables[]= {TSprocesses};

static int TSsort0[]= { NULL }; /* philosophers */

static int TSsort1[]= { NULL }; /* users */

static int TSsort2[]= { /* phil */
  2, 0
  };

static int TSsort3[]= { NULL }; /* service */

static int TSsort4[]= { /* chopstick */
  2, 0
  };

int*  TSsorts[]= {
  TSsort0, TSsort1, TSsort2, TSsort3, TSsort4
  };

int TSsizes[]= {
  2, 1, 0
  };

static int TSsbe0[] = { 1, 2 };
static int TSsbe1[] = { 2 };
static int TSsbe2[] = { NULL };

int *TSsbes[]= {
  TSsbe0, TSsbe1, TSsbe2
  };

eval_f TSevals[]= { NULL };

int specpar = 0;
int max_accepted = 1;
int max_gte = 5;
int max_val = 2;
int max_exp = 3;
boolean g_flag = FALSE;

predicate ftbl[]= { NULL };
coroutine ctbl[]= { c0, c1, c2, c3, c4 };

