Improve `brew leaves` and move it into core

The current criteria for exclusion from `brew leaves` is just "is this formula a dep of any installed formula", but we can do better by respecting the installed option set.

For example, currently if ghostscript and imagemagick are installed, then ghostscript cannot be a leaf because imagemagick has an optional dependency on ghostscript. But if we inspect imagemagick's install receipt, we can avoid this false negative.