sw_sparse.c (626B)
1 /* A SPARSE switch: case values are few and far apart, so the backend lowers it 2 * to a compare-and-branch chain (subs/cmp + b.eq) rather than a jump table. 3 * volatile selector defeats constant folding; each comparison + conditional 4 * branch is really emitted and the branch labels round-trip through `as`. 5 * Selector 1000 hits the case returning 42. Exit code 42. */ 6 int sel(int x) { 7 switch (x) { 8 case 0: 9 return 1; 10 case 100: 11 return 2; 12 case 1000: 13 return 42; 14 case 9999: 15 return 3; 16 default: 17 return 99; 18 } 19 } 20 int test_main(void) { 21 volatile int x = 1000; 22 return sel(x); 23 }