This is most likely because of fissure in ano which means that near the anal opening, due to chronic constipation, sometimes a cut like lesion develops, which leads to severe pain while passing stools(poop), constipation (unable to pass stools) and sometimes blood in stools.
A trial of conservative management ( medicines and lifestyle modification) can be given.
Next Steps
avoid oily and spicy food
consume high fibre diet(bananas) and fluids
syrup cremaffin - 3 tsp at night before sleeping (dose can be reduced if you feel loose motions)
warm sitz bath- most important and most effective (sit in warm water for 10-15 mins 3-4 times every day)
ointment fidonal local application after sitz bath