/* val2.c  2012-12-20 14:23
   Reference executable for validating application profiling tools.
   val2:  two functions with a single invocation and no recursion.

   The call graph is simply
     main->leaffn
   with nearly 100 % of time spent in leaffn.

   Language -std=gnu99 (with gcc-specific attributes).
   Original versions tested:  gcc 4.7.2.
*/

// Configurable INNERLOOP:  how many iterations in leaf function.
#ifndef INNERLOOP
#define INNERLOOP 200000000
#endif

#include <inttypes.h>
#include <math.h>
#include <stdio.h>

uint64_t accumulator=1;
double   adder=0;

__attribute__((noinline)) void leaffn() {
  for (uint64_t looper=0; looper<INNERLOOP; ++looper)
    adder += M_PI*3, accumulator = accumulator*3 + adder;
}

int main() {
  leaffn();
  printf ("%" PRIu64 " %f\n", accumulator, adder);
  return 0;
}
