blob: 33ae856debbd943b29f00a79ed14e2510b258114 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// A function to hook: fib(n) the slow way, kept from being turned into a
// loop so that it makes the 2 fib(n+1) - 1 calls the definition says.
#include <stdio.h>
#include <stdlib.h>
__attribute__((noinline, optnone)) static unsigned long fib(unsigned long n) {
if (n < 2) return n;
return fib(n - 1) + fib(n - 2);
}
int main(int argc, char **argv) {
unsigned long n = argc > 1 ? strtoul(argv[1], NULL, 10) : 10;
printf("fib(%lu) = %lu\n", n, fib(n));
return 0;
}
|