Is it possible to completely reset an iPhone so its software/firmware is guaranteed to be 100% factory fresh? When purchasing a used iPhone with a completely unknown history (which includes the possibility of multiple previous owners), is it possible to reset it and be sure that all software and firmware on it is 100% identical to the factory image?
Please keep in mind that since the history is unknown, it's possible the device was previously jailbroken/unlocked/rooted/etc.
If the answer varies depending on iPhone model, please indicate to which models your answer pertains.
I'm interested in answers for all iPhone models.

Please note:
The question and answers at Is it possible to return the iPhone to its very original factory state? do not help because they do not take in account the possibility of the phone being jailbroken/unlocked/rooted/etc.  Also, that question is ambiguous as to whether or not it applies to both the software and firmware.
No, it’s not possible if the phone has received iOS updates, which it probably has. You may be able to reset it to the factory state of a new iPhone, but not to the factory state of your iPhone, because Apple works hard to ensure that you can’t downgrade iOS to the factory version.