Cut the salt cod into chunks and put them in a large bowl. Add enough water to cover. Put the cod in the refrigerator and let it soak for 48 hours, changing the water at least four times a day. To check that the cod is sufficiently desalted, taste a bit: it should be appealingly briny, but not salty.
Heat the oven to 375°F. Oil a small (4-cup) gratin dish. In a medium saucepan, combine 2 qt. water with the onions, the halved garlic, and bay leaves. Bring to a boil, reduce to a simmer, add the salt cod, and cover the pot tightly. Turn off the heat and let the fish sit in the water just until it can be pulled apart with a fork, 10 to 15 minutes. Remove the fish from the water and set the water aside for cooking the potatoes. When the fish is cool enough to handle, pick out any bones and remove any skin. Flake the fish by rubbing it between your fingers or using a fork or wooden spoon. Transfer to a food processor.
Meanwhile, simmer the potatoes until very tender in the water in which you cooked the fish. Drain the potatoes and mash with a hand masher or ricer. Add 1/3 cup of the milk and 1/4 cup of the olive oil to the potatoes and combine well. Set aside.
In a saucepan, heat another 1/4 cup of the oil over medium low and add the minced garlic. The instant the garlic begins to sizzle, remove the pan from the heat. Add the garlic and oil, along with the salt, to the salt cod in the processor. Combine the remaining 1/3 cup milk and 1/4 cup oil. Turn on the processor and add the milk and olive oil mixture in a slow stream. Continue to process until the mixture is fluffy. Add the salt cod purée to the potato mixture and fold to combine well. Season with pepper. Spoon the mixture into the gratin dish, drizzle with 1 to 2 Tbs. olive oil, and bake until the top begins to brown, 20 to 25 minutes. Serve hot.