// WA-probe: top-8 histogram ONLY (8-way unrolled, like v5's hist_top). Measures hist cost on real data.
typedef unsigned int u32;
static u32 cnt[256];
void sort(unsigned *a, int n) {
int i, j;
for (j = 0; j < 256; j++) cnt[j] = 0;
int n8 = n & ~7;
for (i = 0; i < n8; i += 8) {
cnt[a[i]>>24]++; cnt[a[i+1]>>24]++; cnt[a[i+2]>>24]++; cnt[a[i+3]>>24]++;
cnt[a[i+4]>>24]++; cnt[a[i+5]>>24]++; cnt[a[i+6]>>24]++; cnt[a[i+7]>>24]++;
}
for (; i < n; i++) cnt[a[i] >> 24]++;
a[0] = cnt[0] + cnt[255]; // touch to keep loop live, still WA (unsorted)
}