# Code generation, realistic example of code
type node = record of {val : int, left : node, right : node};

var root : node,t : bool;

func initNode(a : int) : node
var temp : node;
{
  allocate temp;
  temp.left = null;
  temp.right = null;
  temp.val = a;
  return temp;
}
end initNode

func insert(root : node, key : int) : node
{
  if root == null then
    return initNode(key);
  if root.val > key then
    root.left = insert(root.left, key);
  else if root.val < key then
    root.right = insert(root.right, key);
  return root;
}
end insert

func print(root : node) : bool
var t : bool;
{
  if root == null then
    return true;
  t = print(root.left);
  write root.val;
  t = print(root.right);
  return true;
}
end print

root = null;
root = insert(root, 10);
root = insert(root, 5);
root = insert(root, 6);
root = insert(root, 3);
root = insert(root, 4);
root = insert(root, 7);
root = insert(root, 15);
root = insert(root, 19);
root = insert(root, 1);
root = insert(root, 9);
root = insert(root, 20);

t = print(root);
