mgrang added a comment. Thanks escha. It seems Addition Chain Exponentiation is NP-complete. My solution calculates pow(x, n) by computing powers of 2. See: https://en.wikipedia.org/wiki/Exponentiation_by_squaring#Computation_by_powers_of_2 http://reviews.llvm.org/D13994