Definition perm_max (p1 p2 : option permission) : option permission :=
    match p1,p2 with
      | Some Freeable, _ => p1
      | _, Some Freeable => p2
      | Some Writable, _ => p1
      | _, Some Writable => p2
      | Some Readable, _ => p1
      | _, Some Readable => p2
      | Some Nonempty, _ => p1
      | _, Some Nonempty => p2
      | None, None => None
    end.

(* Specifications: *)
Lemma perm_max_comm : forall p1 p2, perm_max p1 p2 = perm_max p2 p1.
Lemma perm_max_result : forall p1 p2 pu (Hmax: perm_max p1 p2 = pu), pu = p1 \/ pu = p2.
Lemma perm_max_ord : forall p1 p2 pu (Hmax: perm_max p1 p2 = pu), Mem.perm_order'' pu p1 /\ Mem.perm_order'' pu p2.