If you really do need to saw off the legs, here a few more ideas that are similar to JACK's answer.
Use these to reattach the legs and have them removable for when you move out. These are half lag screw and half bolt. The lag screw side gets screwed into wood on one side of the connection (usually with a pilot hole drilled first to prevent splitting). The other side gets a nut screwed on. With this being a leg you are reattaching, it would probably need to be a wood insert nut screwed into the wood (again with a pilot hole drilled). These tend to be very sturdy, fairly inexpensive, removable, and can be tightened down fairly tightly to help prevent problems with sheer forces, like sliding the bookcase around. Because this involves screwing the leg back on, you can only use one of these per leg. Depending on the size and shape of the leg, that might be ok or it might be a problem.
Example hanger bolt: https://www.homedepot.com/p/Hillman-1-4-in-20-x-3-in-Hanger-Bolt-12-Pack-44947/204775253
Example wood insert nut: https://www.homedepot.com/p/Everbilt-1-4-in-20-tpi-Solid-Brass-Wood-Insert-Nut-2-Pack-818798/204806598
You could instead go with a cam lock/screw/dowel system. These are typically what you see in low end furniture that you put together yourself. The connections are actually pretty sturdy, even if the furniture itself isn't. This would allow you to have more than one connector per leg, but if you want to slide the bookcase around, these can work themselves loose.
Example cam lock dowel: https://www.lowes.com/pd/Hillman-6-mm-x-45-1-2-mm-Silver-Zinc-Plated-Binder-Interior-Binding-Post-Screws-2-Count/3231534
Example cam lock nut: https://www.lowes.com/pd/Hillman-5-Count-1-4-in-x-1-2-in-Zinc-plated-Joint-Connector-Nut/3234405
Both types of fastener can be tricky to install correctly, but the hanger bolts are a bit easier to deal with. If you get the alignment off, you can often just twist things tighter to make it work. But if they aren't at a straight 90 degree angle to the surface of the wood, you have a problem.
If you get the distance of the cam lock off, you might have to do a bunch of re-drilling and filling holes, so it can get messy real quick.
As good as they are, they aren't as good as solid wood, so if you plan on sliding this bookcase around, you might want to think about adding sliders under the feet before you load it up. You can get them in plastic or felt, depending on the load you are putting on it and the surface it'll be sliding on.
Example plastic sliders: https://www.amazon.com/MAGIC-SLIDERS-02516-Self-Adhesive-Sliding/dp/B00MAGS892/
Example felt sliders: https://www.amazon.com/Yelanon-Furniture-Pads-182-Pieces/dp/B07RNCDVZ5/
Disclaimer: There are obviously many stores, brands, sizes, and other variations of all the products I suggested. I just used the first good examples I found. I'm not recommending stores, specific products, or anything else.