/* This code generated from TC source.  DO NOT EDIT ! */
/* For convensions and C++ interfaces see file `tc.h' */
#ifndef TSYSTEM
#define TSYSTEM
#endif
#include <tc.h>

#include <stdio.h>
#include <stdlib.h>

unsigned cfib (unsigned _n)
{
  return _n < 2 ? _n : cfib(_n - 1) + cfib(_n - 2);
}



#include "gr_fib.ttypes.h"

 void inline __tfun_fib (/* unsigned _n, tout unsigned *_res */
	__fib_args const* _args, __fib_ress* _ress)
{
  if ((_args->_n.get_value()) < 32) {
    *(&_ress->_res.get_value()) = cfib((_args->_n.get_value()));
  } else {
    T_Val< unsigned > res1, res2;
    fib((_args->_n.get_value()) - 1, &res1);
    fib((_args->_n.get_value()) - 2, &res2);
    *(&_ress->_res.get_value()) = res1.get_value(/*R*/) + res2.get_value(/*R*/);
  }
}

int tmain (int argc, char* argv[])
{
  unsigned n;
  T_Val< unsigned > res;
  if (argc < 2) {

    terrprint(
      "Usage:\n"
      "gr_fib <number>\n"
    );

    return -1;
  }
  n = (unsigned)atoi(argv[1]);
  fib(n, &res);
  (volatile unsigned)res.get_value(/*R*/);
  terrprint("fib(%u) = %u\n", n, res.get_value(/*R*/));
  return 0;
}