There has recently been a growing evidence in the blazar observations for the existence of magnetic fields in the extra-galactic regions, where astrophysical processes are hardly responsible for their generation. One natural speculation is to attribute the production of large-scale magnetic fields to inflationary dynamics; however, such attempts have been found extremely challenging due to the strong constraints from the CMB observations. A crucial ingredient to evade such problems is a nontrivial post-inflationary evolution of the produced magnetic fields. For a significant production, the conformal invariance of the U(1) electromagnetic (EM) field must be violated. In the case where the EM field couples to a pseudo-scalar field, the lowest-order interaction allowed by symmetries dynamically breaks parity and induces continuous production of helical EM fields. When the pseudo-scalar is the inflaton, they are further enhanced by parametric resonance during the period of inflaton oscillation and subsequently by a turbulent process called inverse cascade after reheating. In the case of coupling to a scalar field through the kinetic term, on the other hand, the time dependence of the coupling function breaks the conformal invariance and enhances the EM field. Since the magnetic field amplitude is strongly limited by the observations if the scalar field is the inflaton, we consider an additional field that supports the EM production for a fixed duration during and after inflation. I discuss the mechanisms of magnetogenesis and the resultant amplitudes in these models.