Analysis of laser shock experiments on precompressed samples using a quartz reference and application to warm dense hydrogen and helium