Poor guy! I'm so sorry to hear that. There are a few possibilities here.
-He may have a lower back issue that causes pain when he postures to defecate. This is not always visible on x-rays, and sometimes more advanced imaging such as MRI or CT is needed, for which he would need specialty referral.
-He may have some sort of polyp or growth inside the rectum- it could be too deep for the veterinarian to feel. An endoscopy may be needed in order to detect this.
-He may have a problem with his prostate; this is more common in intact male dogs, but can occur in those who have been neutered as well.
-He may have rectal fissures that are not visible- this is not a problem I have seen in dogs, but it is well-known in people.
-His bowel movements may be firm/hard, and painful when he passes them. Or, he may have had a firm/painful one in the past, and now the anticipation of that happening again causes him to yelp.
My recommendations are as follows-
-Increase water intake to help soften stool. This can be done by adding water to his kibble, or giving him canned as well as dry food. Encourage him to drink more water (add ice cubes, offer him water with a little chicken broth (low sodium) throughout the day.
-Sometimes increasing fiber can actually help soften the stool a bit. You can add 1/4 teaspoon of miralax to his food twice daily- give it a few days to see if this helps.
-Stop giving the rawhides- these do not digest well, and can sometimes hurt when passing out through the stool.
-If none of the above are helping, ask your veterinarian about trying a stool softener such as lactulose.
-If none of the above measures help, he may need the additional testing I discussed above (abdominal ultrasound to check prostate, endoscopy to check inside rectum and colon, CT to check his spine).
Has this helped?