Skip to content

Instantly share code, notes, and snippets.

@johnsto
Created January 15, 2014 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnsto/8435431 to your computer and use it in GitHub Desktop.
Save johnsto/8435431 to your computer and use it in GitHub Desktop.
Compiling and decompiling the Fibonacci example on http://decompiler.fit.vutbr.cz/decompilation/
// Fibonacci numbers
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int i, numtimes, number;
unsigned value, fib();
printf("Input number of iterations: ");
scanf ("%d", &numtimes);
for (i = 1; i <= numtimes; i++) {
printf ("Input number: ");
scanf ("%d", &number);
value = fib(number);
printf("fibonacci(%d) = %u\n", number, value);
}
exit(0);
}
unsigned fib(int x) { /* compute fibonacci number recursively */
if (x > 2)
return (fib(x - 1) + fib(x - 2));
else
return (1);
}
//
// This file was generated by the Retargetable Decompiler
// Website: http://decompiler.fit.vutbr.cz
// Copyright (c) 2011-2014 Lissom <decompiler@fit.vutbr.cz>
//
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/* -------- Function Prototypes --------- */
int32_t _____fib(uint32_t plum);
/* ------------- Functions -------------- */
int main(int argc, char **argv) {
printf("Input number of iterations: ");
int32_t apple;
scanf("%d", &apple);
if (apple <= 0) {
// 0x401596
exit(0);
// UNREACHABLE
// branch -> 0x4015a2
}
// 0x4015a2
printf("Input number: ");
int32_t banana;
scanf("%d", &banana);
printf("fibonacci(%d) = %u\n", banana, _____fib(banana));
if (apple <= 1) {
// 0x4015ef
exit(0);
// UNREACHABLE
// branch -> 0x4015fb
}
// 0x4015fb
printf("Input number: ");
scanf("%d", &banana);
printf("fibonacci(%d) = %u\n", banana, _____fib(banana));
if (apple <= 2) {
// 0x401648
exit(0);
// UNREACHABLE
// branch -> 0x401654
}
// 0x401654
printf("Input number: ");
scanf("%d", &banana);
printf("fibonacci(%d) = %u\n", banana, _____fib(banana));
if (apple <= 3) {
// 0x4016a1
exit(0);
// UNREACHABLE
// branch -> 0x4016ad
}
// 0x4016ad
printf("Input number: ");
scanf("%d", &banana);
printf("fibonacci(%d) = %u\n", banana, _____fib(banana));
if (apple < 5) {
// 0x40174e
exit(0);
// UNREACHABLE
}
printf("Input number: ");
scanf("%d", &banana);
printf("fibonacci(%d) = %u\n", banana, _____fib(banana));
int32_t lemon = 6; // 0x40173f
while (lemon <= apple) {
// 0x4016fb
printf("Input number: ");
scanf("%d", &banana);
printf("fibonacci(%d) = %u\n", banana, _____fib(banana));
lemon += 1;
// continue -> 0x4016fb
}
// 0x40174e
exit(0);
// UNREACHABLE
}
int32_t _____fib(uint32_t plum) {
// 0x40175a
int32_t result;
if (plum >= 3) {
int32_t orange = _____fib((int32_t)(plum - 1)); // 0x40176f
result = _____fib(plum - 2) + orange;
// branch -> 0x401796
} else {
result = 1;
}
// 0x401796
return result;
}
/* --------- External Functions --------- */
// void exit (int)
// int printf (const char *restrict, ...)
// int scanf (const char *restrict, ...)
/* --------- Meta-Information ----------- */
// Detected compiler: gcc (mingw32-x86-pe) 4.7.3
// Detected functions: 2 (2 in front-end)
// Decompiler release: v1.5 (Nov 14 2013)
// Decompilation date: Jan 15 2014 13:31:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment