Efficent code writting

In the first set, A & B probably compile to the same code. Did you try compiling them?
The compiler will rewrite your code to its most efficient form ( that it can devise ), which may render all your attempts at optimization equal and of no additional benefit.
B just seems intentionally wasteful as both if & else if call the same function. However it may be more readable to you.

The second set would be equal, and the second B also depends on weather a & b are used elsewhere. I would personally use A, there is no need to store the result as you already know it using the literal in the comparison.