factor out common subexprssion (gcc of course is too stupid to do this ...)