Context. The inner layers of circumstellar envelopes around asymptotic giant branch stars are sites where a variety of processes such as thermochemical equilibrium, shocks induced by the stellar pulsation, and condensation of dust grains determine the chemical composition of the material that is expelled into the outer envelope layers and, ultimately, into interstellar space. Aims. We aim at studying the abundances, throughout the whole circumstellar envelope of the carbon star IRC +10216, of several molecules formed in the inner layers in order to constrain the different processes at work in such regions. Methods. Observations towards IRC +10216 of CS, SiO, SiS, NaCl, KCl, AlCl, AlF, and NaCN have been carried out with the IRAM 30-m telescope in the 80−357.5 GHz frequency range. A large number of rotational transitions covering a wide range of energy levels, including highly excited vibrational states, are detected in emission and serve to trace different regions of the envelope. Radiative transfer calculations based on the LVG formalism have been performed to derive molecular abundances from the innermost out to the outer layers. The excitation calculations include infrared pumping to excited vibrational states and inelastic collisions, for which up-to-date rate coefficients for rotational and, in some cases, ro-vibrational transitions are used. Results. We find that in the inner layers CS, SiO, and SiS have abundances relative to H 2 of 4 × 10 −6 , 1.8 × 10 −7 , and 3 × 10 −6 , respectively, and that CS and SiS have significant lower abundances in the outer envelope, which implies that they actively contribute to the formation of dust. Moreover, in the inner layers, the amount of sulfur and silicon in gas phase molecules is only 27% for S and 5.6% for Si, implying that these elements have already condensed onto grains, most likely in the form of MgS and SiC. Metal-bearing molecules lock up a relatively small fraction of metals, although our results indicate that NaCl, KCl, AlCl, AlF, and NaCN, despite their refractory character, are not significantly depleted in the cold outer layers. In these regions a few percent of the metals Na, K, and Al survive in the gas phase, either in atomic or molecular form, and are therefore available to participate in the gas phase chemistry in the outer envelope.