/*
 * Minimal reproducer — SDCC z80 codegen bug.
 *
 * "global = local" right after "if (local != global)" stores a WRONG value:
 * the SUB used to evaluate the comparison clobbers register A (which still
 * holds `n`), and the store reuses that clobbered A.
 *
 * Build (stock SDCC, no extra flags, no custom toolchain):
 *     sdcc -mz80 -S repro.c
 *
 * Tested with: SDCC 4.5.0 #15242 (Mac OS X x86_64), default options.
 * Also reproduces with --opt-code-speed and with --no-peep
 * (so it is a code-generator bug, not a peephole-optimizer bug).
 *
 * Expected semantics: after update(n), vx == n  whenever n != vx.
 * Actual result:      vx == (unsigned char)(n - old_vx).
 */
unsigned char vx;

void update(unsigned char n)
{
    if (n != vx) {
        vx = n;
    }
}
