/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
     #include <stdio.h>
     #include <stdlib.h>
     #include <setjmp.h>

     jmp_buf env;
     int i = 0;
     main ()
     {
         void exit();

         if(setjmp(env) != 0) {
            int k; 

            printf("value of i on 2nd return from setjmp: %d\n", i);
            i = 2;
            k = setjmp(env);
            printf("k = %d\n", k);
            if(k==0) {
              printf("reset setjmp() \n");
              restore_env();
            }
            else {
              printf("value of i on 3rd return from setjmp: %d\n", i);
              exit(0);
            }
         }
         (void) printf("value of i on 1st return from setjmp: %d\n", i);
         i = 1;
         restore_env();
         /* NOTREACHED */
     }
     int restore_env()
     {
         longjmp(env, 1);
         /* NOTREACHED */
         return 0;   
     }
