The idea behind trying to end factory farming for animals’ sake is that animals who spend their whole lives on factory farms are enduring lives that are not worth living. It is better not to bring creatures into existence who would live net negative lives.
You’re right that extinction is a (very) extreme case. It’s more likely that even with a drastic reduction in factory farming, a small fraction of descendants of farmed species would be preserved—either for farming, or in zoos or similar institutions. After all, they’re easy to domesticate, having been bred over the centuries for precisely those purposes.
How could we know that they are unhappy? Photos of overcrowded farms look terrible, but animals may have different value structure, like:
longer life expectancy than in the forest
guaranteed access to unlimited amounts of food.
Technically, we could have two ways to measure their preferences: do they feel constant pain according to their EEG + do they want to escape at any price and even happy to be slaughtered?