Any male firstborn lamb, kid or calf is automatically sanctified as a firstborn at birth. If the labor is normal, the firstborn is given to the priests, who later on brings it as a sacrifice. The animal is not worked, and even if it becomes blemished, its meat is not sold in the market. If an animal delivering its first young child is in difficult labor and one has to cut off pieces to save the mother, one may cut each limb as it emerges and throw it to the dogs. If the majority of the fetus emerged and it then died, it must be buried, and its mother is now exempt from the law of firstborn.
If an animal's fetus died inside the womb and the shepherd extended his hand into the womb and touched it, the shepherd does not become impure with corpse-impurity. This is derived through logic: if its mother permits the fetus to be eaten, by her slaughter, then certainly it can purify from corpse-impurity. The law for non-kosher animals that are not slaughtered for food should be the same. Rabbi Yose HaGlili disagrees in the case of a non-kosher animal.
Art: Eugène Verboeckhoven - A Sheep And Two Lambs Resting In A Summer Landscape