#include <setjmp.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
jmp_buf env;

int exec_setjmp (int val_max, int base)
{
  int res = -2;
  int val = setjmp(env); // 1 call = 0, first return of longjmp -> 1, après renvoye X^N
  
  if (val < val_max)
    {
      print(val);
      res ++;
      longjmp (env,base*val);
    }
  
  return res;
}

int test_setjmp  ()
{
  quit(exec_setjmp (366,2));
  
  return (1);
  
  /*
  int base = 2;
  int val,res,it;
  
  srand(0);
  
  for (it = 0; it < 10; it ++)
    {
      val = (rand()%1500);
      
      res = exec_setjmp (val,base);

      print(res);
      
      //printf("test_setjmp : log2(%d)=%d (%d)\n",val,res,(unsigned int)log2((double)val));

      if ((unsigned int)log2(val) != res)
	return 0;
    }
  return 1;
  */
}
