// address: 0x10000480 int fib2(int param1) { int g29; // r29 int g3; // r3 int local5; // m[g1 - 20] if (param1 <= 1) { local5 = param1; } else { fib1(); g3 = fib1(); local5 = g29 + g3; } return local5; }
/** address: 0x10000480 */ __size32 fib2(int param1) { int g3; // r3 int g3_1; // r3{5} __size32 g9; // r9 int local5; // m[g1 - 20] if (param1 <= 1) { local5 = param1; } else { g3_1 = fib1(); g3 = fib1(); /* Warning: also results in g9 */ local5 = g3_1 + g3; } return local5; /* WARNING: Also returning: g9 := g9 */ }
// address: 0x10000504 int main(int argc, char *argv[], char *envp[]) { int g3; // r3 int local0; // m[g1 - 24] printf("Input number: "); g9 = scanf("%d", &local0); g3 = fib1(); printf("fibonacci(%d) = %d\n", local0, g3); return 0; }
// Fibonacci tail recursion int fib1(int n, int fib_prev, int fib_post) { #ifdef DEBUG count++; #endif if(n == 0 || n == 1) { return fib_post; } else { return fib1(n -1, fib_post , fib_post + fib_prev); } }
int main(){ long long t1 = clock(); printf("%d\n", fib1(42)); long long t2 = clock(); printf("%d\n", t2 - t1); t1 = clock(); printf("%d\n", fib2(42)); t2 = clock(); printf("%d\n", t2 - t1); return 0; }
int main() { int n; while(1) { scanf("%d",&n); printf("%d\n",fibTailRecursive(n,0,1)); printf("%d\n",fib1(n)); } return 0; }
int main() { int n = 30; fputs("Fibonacci -- cache version\n", stdout); fprintf(stdout, "fib(%d) is %5d\n", n, fib(n)); #ifdef DEBUG fprintf(stdout, "function called count : %d\n", count); count = 0; #endif fputs("Fibonacci -- Tail recursion\n", stdout); fprintf(stdout, "fib(%d) is %5d\n", n, fib1(n, 1, 1)); #ifdef DEBUG fprintf(stdout, "function called count : %d\n", count); #endif return 0; }
int main(int argc, char *argv[]); __size32 fib1(int param1); /** address: 0x080483a0 */ int main(int argc, char *argv[]) { int eax; // r24 int local0; // m[esp - 8] printf("Input number: "); %edx = scanf("%d", &local0); eax = fib1(local0); printf("fibonacci(%d) = %d\n", local0, eax); return 0; } /** address: 0x0804835c */ __size32 fib1(int param1) { int eax; // r24 __size32 eax_1; // r24{9} __size32 edx; // r26 if (param1 > 1) { eax_1 = fib1(param1 - 1); eax = fib1(param1 - 2); /* Warning: also results in edx */ eax += eax_1; } else { eax = param1; }
int fib1(int n) { if(n==1||n==2) return 1; return fib1(n-1)+fib1(n-2); }