I can understand your concern.
What you are suffering is consistent with constipation.
Here are a few things that you may consider.
1. Drink lots of water.
2. Avoid processed foods like stuff made of maida, white bread, pav etc.
3. Have foods with high fiber content.
4. Instead of having 3 full meals, have 5 smaller meals and let two of those 5 meals consist of fruits and vegetables.
5. Syp. Duphalac 15 mins before bed or isagbol husk before bed.
6. One cup of curd twice a day after food.
If it still persists, you need to see a general surgeon in person for further help.
Dr. Anil Kumar Jain.
The pain you are referring to is indeed related to your motions and commonly happens due to constipation. If you are constipated often, then you are bound to get this kind of pain. Hard stools can also cause inflammation in the surrounding intestine and cause pain. Make sure that your stools are soft and that you are not constipated. For that you must drink plenty of water. Eat atleast one fruit in a day preferably banana. Eat at least one portion of salads in your meal. If inspite of AL this the pain persists, feel free to contact me. I will be happy to guide you.