To be clear, is unnecessary pain immaterial or not?
In a financial/economical sense, abused animals are more likely to die prematurely or contract problems that would drop its worth. But, in the case of the more restrictive/'passively abusive' farm factories, space is a premium that outweighs the mortality potential (and the cost of vaccinations/stuff against sickness). There is also the fact that for some farm factory animals, allowing them to outside is very risky, due to possible disease spreading from the local wildlife/avian populations... (hint of anything close to avian influenza = mass genocide of the flocks that even looks like they could have it).
Unnecessary pain would be when the farmhands do things on their own, like hitting the animals and what-not. No company/farmer needs or wants people handling their animals like that, ever. Though, it is easy to tell when your butcher plant calls in and complains about 'black and blue' animals. Or if you do the butchering yourself, you'll clearly see the results of poor/rough handling and abuse.
For example, poultry, it is pretty easy to see bruising and stuff on them after rough handling... Discerning customers/restaurants, will complain about that, ask for a discount and/or return it. (At least in the case of the Chinese customers.)
I do not know the case of factory type cookeries.
So yes, unnecessary pain has a material cost... / not immaterial. (US Courts do 'reward' on pain received too, don't they?)