Anyway, I've decided to investigate the changes applied by mp3gain myself.
I prepared three versions of one file:
nogain.mp3 - freshly encoded file
gain.mp3 - product of "mp3gain -a nogain.mp3" cmd
undo.mp3 - product of "mp3gain -u gain.mp3" cmd
gain.mp3 file isn't really important here - we will be comparing nogain.mp3 and undo.mp3 as they're expected to be identical in order for mp3gain to be called lossless.
First let's take a look at their sizes and md5sums:3b43eb698efee680ce567a63fbd08dc3 mp3nogain.mp3 (7799117 bytes)
a955070c3bba31bb8e5dff1cf2aa4596 mp3gain.mp3 (7799439 bytes)
35fc682308928832547ff43a1bcb9203 mp3undo.mp3 (7799439 bytes)
First major observation is that mp3gain -u doesn't bring the file back to original shape or even size. The size difference gives us hope that it's only some additional data which make the md5sum different.
Let's check it by doing some binary, byte-by-byte comparison with cmp command:
% cmp mp3undo.mp3 mp3nogain.mp3
cmp: EOF on mp3nogain.mp3
Hurray! This indicates that there's no difference between the files but the size (mp3nogain ended first). So basically what makes the files different is only the data in additional 322 bytes at the end).
Let's find out what's in the additional 322 bytes:
% dd if=mp3undo.mp3 bs=1 skip=7799117
APETAGEXÐ" MP3GAIN_MINMAX079,210MP3GAIN_ALBUM_MINMAX037,210
MP3GAIN_UNDO+000,+000,N
REPLAYGAIN_TRACK_GAIN-6.970000 dREPLAYGAIN_TRACK_PEAK1.034387
REPLAYGAIN_ALBUM_GAIN-7.140000 dREPLAYGAIN_ALBUM_PEAK1.050027APETAGEXÐ"€
Which means that mp3gain -u doesn't remove its own metadata written in APE tag while it should.
CONCLUSION
There should be no doubts about mp3gain's losslessness except that it should remove its undo information after executing undo.
UPDATE
OK, it's not that clean I described above, as for mp3gain modified files (gain.mp3 and undo.mp3) madplay throws out the following error at the very end of decoding:
% madplay -vvv -onull: undo.mp3
MPEG Audio Decoder 0.15.0 (beta) - Copyright (C) 2000-2003 Robert Leslie et al.
error: frame 11198: lost synchronization
11198 frames decoded (0:04:52,5), -4,7 dB peak amplitude, 0 clipped samples
which means that the last frame has been somewhat affected. mp3guessenc says that it has been truncated. On the other hand, when you decode nogain.mp3 and undo.mp3 back to WAVs you will find the resulting files to be identical. There are no audible differences, clicks at the end or any other distortions neither. So the final(?) conclusion would be, that mp3gain is rather safe but it should do its job cleaner.
Hope this would be helpful to anybody. Happy New Year!