San Marino has voted overwhelmingly in favor of legalizing abortion in a referendum, overturning a law dating back to 1865.