Ricardo's theory [a 200 year old theory by the "economist" and (literally) con man, Mr. Ricardo] of trade is in many ways the foundation of conventional economic thinking: output and welfare can be increased by removing barriers to markets reaching equilibrium prices. In this case, the barriers are restraints on international trade, and output and welfare are increased by each country specializing in the good(s) in which it has a comparative advantage.
The key fallacy in the argument is the belief that machinery can be switched from one industry to another without loss. They can't. Machines are specific to each industry, a simple reality that mainstream economists have ignored for two centuries.
When you take this into account, machinery is in effect destroyed [or sold and moved to another country] in the less competitive industries when trade is deregulated, and whether trade enhances output and welfare in the long run depends more on investment and economies of scale than on specialization.