December 10, 2003
/* Digital Mars 8.39.1 (2003-12-07) bug report
 *
 *   bad code generated when optimizing (16-bit only)
 *
 * How to repeat:
 *   dmc -ml -o bug01.c
 *   bug01.exe
 *
 * Markus F.X.J. Oberhumer <markus@oberhumer.com>
 *
 * vi:ts=4:et
 */

#include <stdio.h>
#include <assert.h>

static int strength_reduce_bug(int *); /* avoid inlining */

int main()
{
    /* check for the gcc 2.6.3 -fstrength-reduce bug */

    static int x[3];
    static unsigned xn = 3;
    register unsigned j;

    for (j = 0; j < xn; j++)
        x[j] = (int)j - 3;

    assert(!strength_reduce_bug(x));

    return 0;
}

static int strength_reduce_bug(int *x)
{
    return x[0] != -3 || x[1] != -2 || x[2] != -1;
}