Cast macro rewriting