Last branch records div.c example
[Posted March 25, 2016 by jake]
1 /* div.c */
2 volatile int count;
3
4 __attribute__((noinline))
5 int compute_flag(int i)
6 {
7 if (i % 10 < 4) /* ... in 40% of the iterations */
8 return i + 1;
9 return 0;
10 }
11
12 int main(void)
13 {
14 int i;
15 int flag;
16 volatile double x = 1212121212, y = 121212; /* Avoid compiler optimizing away */
17
18 for (i = 0; i < 2000000000; i++) {
19 flag = compute_flag(i);
20
21 /* Some other code */
22 count++;
23
24 if (flag)
25 x += x / y + y / x; /* Execute expensive division if flag is set */
26 }
27 return 0;
28 }