SMS: Discrete circuit optimization