Is there any way to predict the Undefined Behaviour?
NO
Undefined Behavior means that compiler does not need to adhere to any specific behavior, every compiler may or may not show the same behavior. You cannot rely on approximating/predicting outputs of Undefined behavior from the compiler and write a code on the basis of that.
Strictly, avoid writing any code which invokes Undefined Behavior.
Reference:
Undefined behaviour (UB) is defined by the ISO/ANSI C Standard as:
behavior, upon use of a nonportable or erroneous program construct, of erroneous data, or of indeterminately valued objects, for which this International Standard imposes no requirements.
NOTE: Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
Is there any way to predict Implementation defined behaviour?
Yes, If Portability(assurance that your solution works across different compilers in same way) is not your concern.
No, If you are looking for portability.
If you are working on a specific compiler then,and your solution/project needs to only work for that particular compiler and environment then you can take the liberty to use the implementation specific behavior displayed by that compiler on that environment.
This should be an Interesting read:
A Guide to Undefined Behavior in C and C++.