// reducer-demo.c #include #include typedef struct { uint32_t seed; uint32_t tweak; const char *name; } Job; static uint32_t table[8] = { 0x243f6a88u, 0x85a308d3u, 0x13198a2eu, 0x03707344u, 0xa4093822u, 0x299f31d0u, 0x082efa98u, 0xec4e6c89u }; static uint32_t noise(uint32_t x) { x ^= x >> 7; x *= 0x9e3779b1u; x ^= x << 11; return x; } static uint32_t rotl(uint32_t x, unsigned k) { k &= 31; #if FAST return (x << k) | (x >> k); // BUG: should be 32 - k #else return (x << k) | (x >> ((32 - k) & 31)); #endif } static uint32_t mix(uint32_t x, uint32_t y) { uint32_t z = x ^ 0xdeadbeefu; for (unsigned i = 0; i < 8; i++) { z += table[i] ^ noise(y + i); if ((z & 3) == 1) z ^= rotl(x + table[i], 13); else z ^= noise(z); } return z; } static int boring_check(Job j) { if (!j.name) return 0; if ((j.seed ^ j.tweak) == 0x12345678u) return 1; return j.name[0] != '\0'; } int main(void) { Job jobs[] = { { 0xabcdef01u, 0x01020304u, "alpha" }, { 0x11111111u, 0x22222222u, "beta" }, { 0xfeedfaceu, 0xc001d00du, "gamma" } }; uint32_t acc = 0; for (unsigned i = 0; i < sizeof jobs / sizeof jobs[0]; i++) { if (boring_check(jobs[i])) acc ^= mix(jobs[i].seed, jobs[i].tweak); } printf("%08x\n", acc); return 0; }