Suppose company A invented X, but kept it a trade secret. If then company B reinvents X, either using reverse engineering, or completely independently, can company B patent it, and if so, can company B enforce that patent against company A?
The two scenarios -- reverse engineering X or independently inventing X -- are significantly different.
Assuming that X was not publicly available, B could very well independently invent X and be granted a patent on it (i.e., "first to file").
In the of X being made publicly available (as a product sold by A), X itself could not be patented by B. However, if the method of making X was novel and non-obvious in view of what was publicly disclosed, B might be able to obtain a patent on the method of making X.
Yes, B could enforce a granted patent against company A in either case.
Also note that in several court cases, trade secrets that could even theoretically be reverse engineered were deemed to not be protected (as trade secrets) for that very reason.