Search for gravitational waves associated with 39 gamma-ray bursts using data from the second, third, and fourth LIGO runs