So I have degrees in both American law and English history, and did some preliminary research for a dissertation which touched on land inheritance in Late Medieval and Early Modern England. So I have gotten deep into the weeds of this sort of thing and can give you an example system, but I'm operating from memory and conflating several systems in place over centuries in English law, which itself historically had two separate court systems ("law" and "equity") with their own conflicting rules that changed over centuries.
To broadly generalize, with primogeniture, upon failure of a line you go back to the last holder of the thing in question who does have living heirs and trace down to the eldest of the closest male descendants to them. In the fact pattern outlined the abdicator abdicates in favor of their first child. When the first child dies without any descendants we go back up to the abdicator, treat them as dead for the purposes of this inheritance, and it goes to their subsequent child. Sometimes someone might abdicate something on behalf of themselves and all their descendants, but this is clearly not the case outlined as it was one of their descendants who they abdicated in favor of.
In England the crown itself was male preference primogeniture. Noble titles, however, were strict male primogeniture and could not be held by women at all (unless they were a reigning queen, who can sort of be the Duke of Lancaster). Property followed its own rules, but could be bequeathed with a variety of strings attached. Aristocratic families often at some point employed the help of a lawyer to bequeath their property in land to the next generation with the condition of some variation of primogeniture attached ever after. If the family had noble titles, setting up the property to both be inalienable and follow the same inheritance pattern of the primary title would be the norm. In any case, attaching such conditions to property is actually an act of private law, not a public law of the land, and so can have a lot of variation beyond just normal issues of the norm in the time and place. The inheritance of a particular property may have all sorts of eccentric rules attached. In any case this privately contracted "primogeniture", the entail, is the form of "primogeniture" we encounter at the core of so many Jane Austen plots and the like about daughters being thrown out of the family home in favor of some male fourth cousin.
Noble titles could not be inherited up beyond the person who first received them. If the original recipient and all their male heirs are dead, the title fails. In England this typically meant that the husband of the last holder's closest female relative would get a new creation of the title so that it would stay with her and her sons, provided the family had the good will or influence with the monarchy to make that happen. In your scenario the second child is the heir for whatever the first child received from the abdicator, but not necessarily for any other property, titles, etc. they may have acquired.
Looking beyond England, the inheritance rules of Royal titles and other titles that involved actual rule were much more complicated because, whatever the inheritance law theoretically was, the heir who could enforce their claim through political or military influence ultimately got the title.