const n:int = 100

fun f(a:int^n at r) returns (o:int^n at r)
let
  o = [ a with [0] = 3 ]
tel

fun g(a:int^n at r) returns (o:int^n at r)
let
  o = [ a with [n-1] = 10 ]
tel

node autom(a:int^n at r) returns (o:int^n at r; u:int)
let
  automaton
    state S1
    do
      o = g(a)
    until true then S2

    state S2
    do
      o = f(a)
    until false then S1
  end;
  u = a[0]
tel

node autom_last() returns (u1,u2:int)
var last o : int^n at r = 0^n;
let
  automaton
    state S1
    do
    until true then S2

    state S2
    var u:int;
    do
      (o,u) = autom(last o)
    until false then S1
  end;
  u1 = o[0];
  u2 = o[n-1];
tel

node main() returns (u1,u2:int)
let
  (u1,u2) = autom_last()
tel
