  Red supergiant stars (RSGs) and yellow hypergiant stars (YHGs) are believed
to be the high-mass counterparts of stars in the AGB and early post-AGB phases.
We study the mass-loss in the post main-sequence evolution of massive stars,
through the properties of their envelopes in the intermediate and warm gas
layers. These are the regions where the acceleration of the gas takes place and
the most recent mass-loss episodes can be seen. We used the HIFI instrument
on-board the Herschel Space Observatory to observe sub-mm and FIR transitions
of CO, water, and their isotopologues in a sample of two RSGs (NML Cyg and
Betelgeuse) and two YHGs (IRC+10420 and AFGL 2343) stars. We present an
inventory of the detected lines and analyse the information revealed by their
spectral profiles. On the basis of the results presented in an earlier study,
we model the CO and 13CO emission in IRC+10420 and compare it to a set of lines
ranging from the mm, to the FIR. Red supergiants have stronger high-excitation
lines than the YHGs, indicating that they harbour dense and hot inner shells
contributing to these transitions. Consequently, these high-J lines in RSGs
originate from acceleration layers that have not yet reached the circumstellar
terminal velocity and have narrower profiles than their flat-topped lower-J
counterparts. The YHGs tend to lack this inner component, in line with the
picture of detached, hollow envelopes derived from studies at longer
wavelengths. NH3 is only detected in two sources (NML Cyg, IRC+10420), which
are also observed to be the strongest water-line emitters of the studied
sample. In contrast, OH is detected in all sources and does not seem to
correlate with the water line intensities. We show that the IRC+10420 model
derived solely from mm low-J CO transitions is capable of reproducing the
high-J transitions when the temperature in the inner shell is simply lowered by
about 30%.
