How? See my response above. We humans have chosen to use them for different purposes (companionship vs. meat) but that doesn’t mean they are biologically different or that farm animals don’t have emotions and feel pain just like dogs and cats do.
Farm animals are livestock.
Pets, regardless of species, are not. Most people who have hobby farms, in my experience, have pets. Working farms/ranches have livestock.
I would argue that the demarcation between sensory acknowledgement and pain for a cow or most livestock is orders of magnitude away from that of a dog or human.
Of course, natural behavior, balance point, etc, of course, are a much better method of working cattle than, say, electric prods and blunt physical force.