Write a primitive optimizer