Company reshuffling and layoffs are always painful. I was part of two such events in my job history. In the first one, we were just laid off, and given severance pays. Our jobs were being offloaded to India. The second one, we were laid off, but immediately absorbed by the company that would handle our work. My biggest advice is always make and keep your 'receipts'. By receipts, I meant a list of work that you do, and accomplishment you have. You always want to be indispensable to the company. Not only can this be used in that scenario, it can be useful when looking for a promotion. If it looks like your work is becoming redundant or can be replaced by AI, it would be ideal to get ahead of that by getting training, starting projects, or transferring to a more stable department.
Everything needs a paper trail. I try to ensure that the work I do has visible tangibles that if checked, will show that not only have I been doing my work, but I have been value-adding to what I do throughout the organization. The other benefit of this is, work is more enjoyable :)