Brainstorm says "Draw three cards, then put two cards from your hand on top of your library in any order."
If I have no cards in my library when I cast Brainstorm, do I lose? I imagine so - it feel pretty weird if I don't - but apparently state-based actions aren't checked during spell resolution, and by the time Brainstorm resolves I no longer have an empty library, so just checking.