First-principles theory of infrared vibrational spectroscopy of metals and semimetals: Application to graphite