Where do IceCube neutrinos come from? Hints from the diffuse gamma-ray flux