Hi thanks your query posted to health magic,
The condition you described is fissure in ano
in which there are formation of ulcer because of hard stool.
Whenever child trying to defecate this ulcer cause pain and child do not want to defecate and is formation of gas that leads trouble. this condition may heals when stool become soft and child get no pain during defecation, for this you need regular stool softener
, pain killer and ointment smooth locally before and after defecation. and in future such condition do not occur for which you require dietary modification.