/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define REP 10
#define M 10000
#define N 1000000

void testint()
{
    time_t t1,t2;
    int i,j,sum;
    t1 = time(NULL);
    for(i = 0; i < M; i++)
    {
        sum = i;
        for(j = 0; j < N; j++)
        {
            sum = ((sum + 1) * 2 + 1) / 2;
        }
        if(sum != (i + N))
        {
            printf("Error\n");
            exit(0);
        }
    }
    t2 = time(NULL);
    printf("%d seconds\n",t2-t1);
}

int main()
{
    int i;
    for(i = 0; i < REP; i++)
    {
        testint();
    }
    return 0;
}
