Man, it sucks to get fired. You'll probably go through a dozen different emotions in the first five minutes. Even when you expect it - maybe you've had some bad performance reviews or the company is obviously in deep trouble - when it finally happens it's an emotional hit. If you don't expect it, it's even worse. These days companies are terrified of lawsuits, so if your performance isn't stellar, you're likely to get a couple of warnings and be put on a performance improvement plan. You'll at least have some hint that things aren't right. But in a mass layoff or bankruptcy, there may be little or no warning. (Companies in trouble don't want to advertise it, because then vendors may stop dealing with them or demand cash up front, making the financial situation worse).
Unfortunately, there are lots of reasons to get fired that have nothing to do with your performance. If your company gets acquired by or merged into another you may find that your job is already being done by someone else - and this is particularly true if you are in a back office job like HR or accounting or legal. Companies today don't have a lot of tolerance for unprofitable businesses so they'll exit them at the first signs of trouble and fire the employees. And of course we hear about 'offshoring' all the time, where jobs are moved to countries with lower labor costs. So there may be nothing you can do to save your job. In all of these situations you're not likely to get a lot of warning before being fired.
Nothing can make getting fired easier, but I have some advice for handling the situation.