void switch_test() {
  int i;
  for (i = 0; i < 15; i++) {
    switch (i) {
    case 0:
    case 1:
      printf("a");
      break;
    default:
      printf("%d", i);
      break;
    case 8 ... 12:
      printf("c");
      break;
    case 3:
      printf("b");
      break;
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<switch_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0xf,-0x4(%rbp)
jge    11bf <switch_test+0xaf>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x2,%eax
jb     1162 <switch_test+0x52>
jmp    113d <switch_test+0x2d>
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
je     119e <switch_test+0x8e>
jmp    114e <switch_test+0x3e>
mov    -0x8(%rbp),%eax
add    $0xfffffff8,%eax
sub    $0x5,%eax
jb     118b <switch_test+0x7b>
jmp    1175 <switch_test+0x65>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ac <switch_test+0x9c>
mov    -0x4(%rbp),%esi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ac <switch_test+0x9c>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ac <switch_test+0x9c>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <switch_test+0xa1>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <switch_test+0xf>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<switch_test>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
xor    %ebx,%ebx
jmp    1142 <switch_test+0x22>
nop
mov    $0x63,%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    $0xf,%ebx
je     117a <switch_test+0x5a>
lea    -0x8(%rbx),%eax
cmp    $0x5,%eax
jb     1130 <switch_test+0x10>
cmp    $0x2,%ebx
jae    1160 <switch_test+0x40>
mov    $0x61,%edi
jmp    1135 <switch_test+0x15>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x3,%ebx
jne    116c <switch_test+0x4c>
mov    $0x62,%edi
jmp    1135 <switch_test+0x15>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    113a <switch_test+0x1a>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"c\00"
@.str.3 = [2 x i8] c"b\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @switch_test() {
%1 = alloca i32
store i32 0, i32* %1
br label %2
2: ; preds = %17, %0
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 15
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = load i32, i32* %1
switch i32 %6, label %9 [
i32 0, label %7
i32 1, label %7
i32 8, label %12
i32 9, label %12
i32 10, label %12
i32 11, label %12
i32 12, label %12
i32 3, label %14
]
7: ; preds = %5, %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
9: ; preds = %5
%10 = load i32, i32* %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %16
12: ; preds = %5, %5, %5, %5, %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %12, %9, %7
br label %17
17: ; preds = %16
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %2
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
define void @switch_test() {
br label %1
1: ; preds = %0, %11
%2 = phi i32 [ 0, %0 ], [ %12, %11 ]
switch i32 %2, label %5 [
i32 0, label %3
i32 1, label %3
i32 8, label %7
i32 9, label %7
i32 10, label %7
i32 11, label %7
i32 12, label %7
i32 3, label %9
]
3: ; preds = %1, %1
%4 = tail call i32 @putchar(i32 97)
br label %11
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %11
7: ; preds = %1, %1, %1, %1, %1
%8 = tail call i32 @putchar(i32 99)
br label %11
9: ; preds = %1
%10 = tail call i32 @putchar(i32 98)
br label %11
11: ; preds = %3, %5, %7, %9
%12 = add nuw nsw i32 %2, 1
%13 = icmp eq i32 %12, 15
br i1 %13, label %14, label %1
14: ; preds = %11
%15 = tail call i32 @putchar(i32 10)
ret void
}