D: An intense 'retrain' signal send to the brain.

The purpose of pain is to train (or retrain) the brain against repeating the behavior which led to the current situation.

Normally pain is an indication that something is reducing the reproductive potential of the organism (the gene-host). It might be a sabre-tooth tiger biting it's arm off, a hand in a hot fire, or a spear piercing the flesh.

Avoiding a repetition of that behavior is normally highly desirable, and training the brain to avoid repeating the experience is an effective evolutionary strategy.

Strictly, pain is not an emotion (being more physical in nature), but it is useful to classify it as such.