Merck & Co. is in advanced talks to buy drugmaker Terns Pharmaceuticals Inc., according to people familiar with the matter.