A primordial origin for molecular oxygen in comets: a chemical kinetics study of the formation and survival of O2 ice from clouds to discs