summaryrefslogtreecommitdiff
path: root/targets/agent_fib.c
diff options
context:
space:
mode:
Diffstat (limited to 'targets/agent_fib.c')
-rw-r--r--targets/agent_fib.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/targets/agent_fib.c b/targets/agent_fib.c
new file mode 100644
index 0000000..33ae856
--- /dev/null
+++ b/targets/agent_fib.c
@@ -0,0 +1,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;
+}