undigested food rots somewhat on the way through and bacteria eats it and makes more gas. this is particularly true with carbs that don't digest or human-indigestible carbs (sugar alcohols for example). if it's fully digested (and absorbed) it's mostly fibre coming out.
I had massive problems (celiac) about 20 years ago with digestion, went to a doctor specializing in it.
Aww the truth is not as fun as the speculation sometimes I suppose. Glad you got it sorted, celiacs is fucking gnarly
it's complicated though, gas. what I said is surely not the entire story.
last fall I was super into winter squash. my husband wasn't into the farts that resulted. 😂 I cut back and it went away.