namespace; include rt; // a 256-word sweep through a heap pointer, with bounds checks (the default) and without // (unbounded): each pass adds every word of the block 1000 times. the index is variable // and the block is reached through a pointer, so the checked version keeps its checks. // input: a letter (c checked, u unbounded, z none) and how many times to run it. int sweep(int* p, int n) { int s = 0; for (int k = 0; k < 1000; k++) for (int i = 0; i < n; i++) s = s + p[i]; return s; } unbounded int sweepu(int* p, int n) { int s = 0; for (int k = 0; k < 1000; k++) for (int i = 0; i < n; i++) s = s + p[i]; return s; } fn main() { int* p = rt.new(256); for (int i = 0; i < 256; i++) p[i] = i; let which = rt.get_c(), reps = 0, ch = rt.get_c(), r = 0; while (ch >= '0' && ch <= '9') { reps = reps * 10 + ch - '0'; ch = rt.get_c(); } while (reps > 0) { if (which == 'c') r = sweep(p, 256); if (which == 'u') r = sweepu(p, 256); reps--; } rt.put_n(r); rt.put_c(10); rt.free(p); return 0; }