However, just because in the first code there's an expression that is repeated multiple times it doesn't mean that the hardware is going to evaluate it over and over. An optimizing compiler will typically remove the repeated code thanks to common subexpression elimination or related techniques.