# include "lbc.hh"

value     v[3];
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;

    mkpe (b, 2, 7);
    gts = b->gte;
    gts[1] = TRUE;
    gts[2] = TRUE;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 2: {
    mkpe (b, 3, 4);
    gts = b->gte;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 3: {
    v[0] = (udatum)one ();
    if (M->rav[0] != NULL) {
      ud_free (1, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 1;
    c1 (b);
    break;
  }
  case 4: {
    mkpe (b, 5, 6);
    gts = b->gte;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 5: {
    push_gte (2);
    b = mkre (b, 1);
    v[0] = (udatum)one ();
    if (M->rav[0] != NULL) {
      ud_free (1, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  case 6: {
    push_gte (2);
    b = mkre (b, 1);
    v[0] = (udatum)succ (one ());
    if (M->rav[0] != NULL) {
      ud_free (1, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 2;
    c2 (b);
    break;
  }
  case 7: {
    b = mkhd (b, 8);
    gts = b->fth->gte;
    gts[3] = TRUE;
    M = b->frm;

    mkpe (b, 9, 10);
    gts = b->gte;
    gts[3] = TRUE;
    c0 (b->sons);
    b = b->sons->bth;
    goto again;
  }
  case 9: {
    push_gte (1);
    push_gte (3);
    b = mkre (b, 2);
    if (M->rav[0] != NULL) {
      ud_free (1, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->ent = 0;
    M->but = 3;
    c3 (b);
    break;
  }
  case 10: {
    push_gte (3);
    push_gte (2);
    b = mkre (b, 2);
    v[0] = ud_copy (1, M->rav[0]);
    if (M->rav[0] != NULL) {
      ud_free (1, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->rav[0] = v[0];
    v[0] = NULL;
    assert (M->rav[0] != NULL);
    M->ent = 0;
    M->but = 4;
    c4 (b);
    break;
  }
  }
}

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

  switch (M->ent) {
  case 0: {
    mkdl (b, 1, rand()/500000000);
    break;
  }
  case 1: {
    mkso (ud_copy (1, M->rav[0]));
    mkad (b, 2, 1, 1, 0, -1, 0);
    break;
  }
  case 2: {
#line 26 "p2c.lot"
printf ("send %d\n", pnumber ((kdatum)xto[0]));
    v[0] = (udatum)succ (kd_copy ((kdatum)M->rav[0]));
    if (M->rav[0] != NULL) {
      ud_free (1, 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
c2 (b)
  board b;
{
  again: 
  M = b->frm;

  switch (M->ent) {
  case 0: {
    mkdl (b, 1, 2*pnumber((kdatum)M->rav[0]));
    break;
  }
  case 1: {
    mkmo (1);
    mkad (b, 2, 1, 1, 0, -1, 0);
    break;
  }
  case 2: {
#line 32 "p2c.lot"
printf ("  %d:", pnumber ((kdatum)M->rav[0]));
	      printf (" recv %d\n", pnumber ((kdatum)xto[0]));
    v[0] = ud_copy (1, M->rav[0]);
    for (i = 0; i < 2; i++)
      if (M->rav[i] != NULL) {
        ud_free (TSsorts[2][i], M->rav[i]);
        M->rav[i] = 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: {
    mkmo (0);
    mkad (b, 1, 1, 1, 0, -1, 0);
    break;
  }
  case 1: {
    mkso (ud_copy (1, M->rav[0]));
    mkad (b, 2, 2, 1, 0, -1, 0);
    break;
  }
  case 2: {
    if (M->rav[0] != NULL) {
      ud_free (1, M->rav[0]);
      M->rav[0] = NULL;
    }
    M->ent = 0;
    goto again;
  }
  }
}

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

  switch (M->ent) {
  case 0: {
    mkmo (1);
    mkad (b, 1, 1, 1, 0, -1, 0);
    break;
  }
  case 1: {
    mkdl (b, 2, pnumber((kdatum)M->rav[0]));
    break;
  }
  case 2: {
    mkso (ud_copy (1, M->rav[1]));
    mkad (b, 3, 2, 1, 0, -1, 0);
    break;
  }
  case 3: {
    v[0] = ud_copy (1, M->rav[0]);
    for (i = 0; i < 2; i++)
      if (M->rav[i] != NULL) {
        ud_free (TSsorts[4][i], M->rav[i]);
        M->rav[i] = 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[]= { /* producer_2_consumer */
  1, 0
  };

static int TSsort1[]= { /* producer */
  1, 0
  };

static int TSsort2[]= { /* consumer */
  1, 1, 0
  };

static int TSsort3[]= { /* fast_buffer */
  1, 0
  };

static int TSsort4[]= { /* slow_buffer */
  1, 1, 0
  };

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

int TSsizes[]= {
  1
  };

static int TSsbe0[] = { 1 };

int *TSsbes[]= {
  TSsbe0
  };

eval_f TSevals[]= { NULL };

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

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

