Maybe we can reach a stage someday where the amount of pain (and other harms) experienced is drastically reduced, but it will never be eliminated as long as the interests nonhumans have (in avoiding pain, along with other interests), are inferior to those of their "rightful" owners. As long as the scales tip in the balance of human interests, our interest in cheap flesh, eggs, and dairy products will trump some of the most fundamental nonhuman interests, including that of survival, which you sell short here. Animals' ability to experience pain (due to their sentience) is an evolutionary development that serves as a means to the end of staying alive. Ignoring that interest by killing them is a harm to them, plain and simple, and it's entirely unnecessary!
If we stop breeding animals into existence, which we would do if they were no longer our property, some would go "extinct", but it's not like most of the animals we exploit for food are found naturally in the wild anyway. They have been enhanced through selective breeding (and genetic tinkering) for generations, and are in many ways man-made creations. There is no harm in letting that practice end.