Garlic is Allium sativum, and the chemistry behind its reputation is well characterised and slightly counter-intuitive.
Intact garlic contains almost no allicin. What it contains is alliin, an odourless sulfoxide, held separately from the enzyme alliinase. When the clove is crushed or cut, the cell compartments break, the enzyme meets the substrate, and allicin is generated within seconds. This is a chemical defence system that fires on damage. It also means that how garlic is prepared changes what it delivers: heat denatures alliinase, so garlic cooked whole and garlic crushed and rested before cooking are not pharmacologically equivalent.
Allicin has demonstrable antibacterial and antifungal activity in vitro, which was investigated seriously in the early twentieth century and again during the world wars when antibiotics were scarce or unavailable. It is unstable, breaking down rapidly into a range of sulfur compounds, which limits what it can do inside a body. Evidence for garlic supplements affecting blood pressure or cholesterol is mixed and the effects, where found, are small.
So the folk reputation as a defence against infection is not baseless, and it is also not a modern claim: it is old, widespread and independently arrived at across Europe, the Middle East and Asia. Culpeper calls it the poor man's treacle, treacle here being theriac, the classical compound antidote to poison, and assigns it to Mars on its heat and pungency. Sharpness of taste is the recurring signature of the whole Mars group in his scheme.