int foo(unsigned i) {
  void *addrs[] = {&&L1, &&L2, &&L3, &&L4, &&L5};
  int res = 1;
  goto *addrs[i];
L5:
  res *= 11;
L4:
  res *= 7;
L3:
  res *= 5;
L2:
  res *= 3;
L1:
  res *= 2;
  return res;
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0x64(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0x52(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0x40(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0x2e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0x1c(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x40(%rbp)
jmp    1193 <foo+0x93>
imul   $0xb,-0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
imul   $0x7,-0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
imul   $0x5,-0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
imul   $0x3,-0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
pop    %rbp
ret
mov    -0x40(%rbp),%rax
jmp    *%rax

x86 assembly (clang, -O2):
<foo>:
lea    0x57(%rip),%rax
movq   %rax,%xmm0
lea    0x43(%rip),%rax
movq   %rax,%xmm1
punpcklqdq %xmm0,%xmm1
movdqa %xmm1,-0x28(%rsp)
lea    0x44(%rip),%rax
movq   %rax,%xmm0
lea    0x31(%rip),%rax
movq   %rax,%xmm1
punpcklqdq %xmm0,%xmm1
movdqa %xmm1,-0x18(%rsp)
lea    0x29(%rip),%rax
mov    %rax,-0x8(%rsp)
mov    %edi,%eax
jmp    *-0x28(%rsp,%rax,8)
mov    $0x1,%eax
add    %eax,%eax
ret
mov    $0x3,%eax
add    %eax,%eax
ret
mov    $0x1,%eax
jmp    1179 <foo+0x79>
mov    $0x7,%eax
jmp    1179 <foo+0x79>
mov    $0x4d,%eax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,2),%eax
add    %eax,%eax
ret

LLVM IR (-O0):
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca [5 x i8*]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [5 x i8*]* %3 to i8*
%6 = bitcast i8* %5 to [5 x i8*]*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 0
store i8* blockaddress(@foo, %28), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 1
store i8* blockaddress(@foo, %25), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 2
store i8* blockaddress(@foo, %22), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 3
store i8* blockaddress(@foo, %19), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i32 0, i32 4
store i8* blockaddress(@foo, %16), i8** %11
store i32 1, i32* %4
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %13
%15 = load i8*, i8** %14
br label %32
16: ; preds = %32
%17 = load i32, i32* %4
%18 = mul nsw i32 %17, 11
store i32 %18, i32* %4
br label %19
19: ; preds = %16, %32
%20 = load i32, i32* %4
%21 = mul nsw i32 %20, 7
store i32 %21, i32* %4
br label %22
22: ; preds = %19, %32
%23 = load i32, i32* %4
%24 = mul nsw i32 %23, 5
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %32
%26 = load i32, i32* %4
%27 = mul nsw i32 %26, 3
store i32 %27, i32* %4
br label %28
28: ; preds = %25, %32
%29 = load i32, i32* %4
%30 = mul nsw i32 %29, 2
store i32 %30, i32* %4
%31 = load i32, i32* %4
ret i32 %31
32: ; preds = %1
%33 = phi i8* [ %15, %1 ]
indirectbr i8* %33, [label %28, label %25, label %22, label %19, label %16]
}

LLVM IR (-O2):
define i32 @foo(i32 %0) {
%2 = alloca [5 x i8*]
%3 = bitcast [5 x i8*]* %2 to <2 x i8*>*
store <2 x i8*> <i8* blockaddress(@foo, %18), i8* blockaddress(@foo, %16)>, <2 x i8*>* %3
%4 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 2
%5 = bitcast i8** %4 to <2 x i8*>*
store <2 x i8*> <i8* blockaddress(@foo, %13), i8* blockaddress(@foo, %11)>, <2 x i8*>* %5
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 4
store i8* blockaddress(@foo, %10), i8** %6
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %2, i64 0, i64 %7
%9 = load i8*, i8** %8
indirectbr i8* %9, [label %18, label %16, label %13, label %11, label %10]
10: ; preds = %1
br label %11
11: ; preds = %10, %1
%12 = phi i32 [ 77, %10 ], [ 7, %1 ]
br label %13
13: ; preds = %11, %1
%14 = phi i32 [ %12, %11 ], [ 1, %1 ]
%15 = mul nuw nsw i32 %14, 15
br label %16
16: ; preds = %13, %1
%17 = phi i32 [ %15, %13 ], [ 3, %1 ]
br label %18
18: ; preds = %16, %1
%19 = phi i32 [ 1, %1 ], [ %17, %16 ]
%20 = shl nuw nsw i32 %19, 1
ret i32 %20
}