Quantum state preparation and macroscopic entanglement in gravitational-wave detectors