+ return NULL;
+}
+
+
+/* A comparison function used to sort cells in a binary tree.
+ Only the innermost value needs to be compared, because no
+ two cells with similar outer values will appear in the same
+ tree/map. */
+static int
+cell_compare_3way (const struct bt_node *a,
+ const struct bt_node *b,
+ const void *aux UNUSED)
+{
+ const struct cell *fa = BT_DATA (a, struct cell, bt_node);
+ const struct cell *fb = BT_DATA (b, struct cell, bt_node);
+
+ assert (fa->not_wild == fb->not_wild);
+ int vidx = count_one_bits (fa->not_wild) - 1;
+ assert (fa->vars[vidx] == fb->vars[vidx]);
+
+ return value_compare_3way (&fa->values[vidx],
+ &fb->values[vidx],
+ var_get_width (fa->vars[vidx]));
+}
+
+/* A comparison function used to sort cells in a binary tree. */
+static int
+compare_instance_3way (const struct bt_node *a,
+ const struct bt_node *b,
+ const void *aux UNUSED)
+{
+ const struct instance *fa = BT_DATA (a, struct instance, bt_node);
+ const struct instance *fb = BT_DATA (b, struct instance, bt_node);
+
+ assert (fa->var == fb->var);
+
+ return value_compare_3way (&fa->value,
+ &fb->value,
+ var_get_width (fa->var));
+}
+
+
+static void arrange_cells (struct workspace *ws,
+ struct cell *cell, const struct mtable *table);
+
+
+/* Iterate CONTAINER's map inserting a copy of its elements into
+ CONTAINER's binary tree. Also, for each layer in TABLE, create
+ an instance container, containing the union of all elements in
+ CONTAINER. */
+static void
+arrange_cell (struct workspace *ws, struct cell_container *container,
+ const struct mtable *mt)
+{
+ struct bt *bt = &container->bt;
+ struct hmap *map = &container->map;
+ bt_init (bt, cell_compare_3way, NULL);