this is Jubi's undefined behavior patch plus a few new test cases of my own

the purpose of this code is to teach Souper about more undefined behavior and
also to factor out the UB conditions in such a way that they can be called
from the code that will be used to fix issue 13