Decompiler Desquirr Test

Program-Transformation.Org: The Program Transformation Wiki
These results are from David's masters theses, Figure 5.2.

Fibonacci

David apparently used the same 80286 binary file as was used to test dcc. The original C source code is:

int main()
{ 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(x)                 /* compute fibonacci number recursively */
int x;
{
    if (x > 2)
        return (fib(x - 1) + fib(x - 2));
    else
        return (1);
}

The decompiled output is as follows:

sub 10291:
  _printf("Input number of iterations: ");
  ax = _scanf("%d", & var_2);
  si = 1;
  goto loc_102DD;

loc 102AF:
  _printf("Input number: ");
  scanf("%d", & var_4);
  var_6 = sub_102EB(var_4);
  ax = _printf("fibonacci(%d) = %u\n", var_4, var_6);
  si = si + 1;

loc 102DD:
  if (si <= var_2) goto loc_102AF;

  _exit(0);
  return ax;


sub_102EB:
  if (arg 0 <= 2) goto loc_10313;

  dx = sub_102EB(arg_0 - 1);
  ax = sub_102EB(arg_0 + 0xfffe);
  ax = dx + ax;
  goto loc 10318;

  goto loc 10318;

loc_10313:
  ax = 1;
  goto loc_10318;

loc_10318:
  return ax;

Registers are visible; variables, procedures and parameters are not declared. Control flow is limited to if (...) goto label; Actual parameters are recovered well.

Palindrome test

The original source code is:

#include <stdio.h>
#include <string.h>
#include <malloc.h>

void rev(char* source, char* destination)
{
  char* tmp = destination + strlen(source);
  for (*tmp-- = 0; *source; *tmp-- = *source++)
    ;
}

int main(int argc, char**argv)
{
  char* original = NULL;
  char* reverse = NULL;

  if (argc < 2)
  {
    original = "nitalarbralatin";

  }
  else
  {
    original = argv[1];
  }

  reverse = malloc(strlen(original)+1);

  rev(original, reverse);
  if (0 == strcmp(original, reverse))
  {
    printf("%s is a palindrome\n", original);
  }
  else
  {
    printf("Try again!\n");
  }

  free(reverse);

  return 0;
}

The decompiled output is:

sub_401150:
  bx = arg_0;
  ax = _strlen(bx) + arg_4;
  * ax = 0;
  ax = ax - 1;
  goto loc_40116E;

loc_401167:
  dl = * bx;
  bx = bx + 1;
  ax = ax - 1;
  * (ax + 1) = dl;

loc_40116E:
  if ((* bx) != 0) goto loc_401167;

  return ax;


_main:
  if (argc >= 2) goto loc_401188;

  bx = "nitalarbralatin";
  goto loc_40118E;

loc_401188:
  bx = * (argv + 4);

loc_40118E:
  si = _malloc(_strlen(bx) + 1);
  sub_401150(bx, si);
  if (_strcmp(bx, si) != 0) goto loc_4011C7;

  _printf("%s is a palindrome\n", bx);
  goto loc_4011D2;

loc_4011C7:
  _printf("Try again!\n");

loc 4011D2:
  _free(si);
  return 0;

-- MikeVanEmmerik - 20 Mar 2003
CategoryDecompilation

Transform.DecompilerDesquirrTest moved from Transform.DecompilationDesquirr on 20 Mar 2003 - 03:05 by MikeVanEmmerik - put it back