#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int bar(int);
int /*<<< orphan*/ bar0(int /*<<< orphan*/);
int /*<<< orphan*/ bar1(int);
int /*<<< orphan*/ bar2(int);
int /*<<< orphan*/ bar3(int);
int /*<<< orphan*/ bar4(int);
int /*<<< orphan*/ bar5(int);
int /*<<< orphan*/ bar6(int);
int /*<<< orphan*/ bar7(int);
int foo(int i) {
  switch (i) {
  case 0:
    bar0(0);
    return 0;
  case 1:
    bar1(1);
    return 1;
  case 2:
    bar2(2);
    return 2;
  case 3:
    bar3(3);
    return 3;
  case 4:
    bar4(4);
    return 4;
  case 5:
    bar5(5);
    return 5;
  case 6:
    bar6(6);
    return 6;
  case 7:
    bar7(7);
    return 7;
  default:
    return bar(i);
  }
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x7,%rax
ja     126d <foo+0xdd>
mov    -0x10(%rbp),%rax
lea    0xe49(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %edi,%edi
call   1030 <bar0@plt>
movl   $0x0,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x1,%edi
call   1080 <bar1@plt>
movl   $0x1,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x2,%edi
call   1040 <bar2@plt>
movl   $0x2,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x3,%edi
call   1090 <bar3@plt>
movl   $0x3,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x4,%edi
call   1060 <bar4@plt>
movl   $0x4,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x5,%edi
call   10b0 <bar5@plt>
movl   $0x5,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x6,%edi
call   1050 <bar6@plt>
movl   $0x6,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    $0x7,%edi
call   10a0 <bar7@plt>
movl   $0x7,-0x4(%rbp)
jmp    1278 <foo+0xe8>
mov    -0x8(%rbp),%edi
call   1070 <bar@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
cmp    $0x7,%edi
ja     11b3 <foo+0x23>
push   %rbx
mov    %edi,%eax
lea    0xe61(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <bar0@plt>
jmp    122d <foo+0x9d>
jmp    1070 <bar@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
call   1080 <bar1@plt>
jmp    122d <foo+0x9d>
mov    $0x2,%ebx
mov    $0x2,%edi
call   1040 <bar2@plt>
jmp    122d <foo+0x9d>
mov    $0x3,%ebx
mov    $0x3,%edi
call   1090 <bar3@plt>
jmp    122d <foo+0x9d>
mov    $0x4,%ebx
mov    $0x4,%edi
call   1060 <bar4@plt>
jmp    122d <foo+0x9d>
mov    $0x5,%ebx
mov    $0x5,%edi
call   10b0 <bar5@plt>
jmp    122d <foo+0x9d>
mov    $0x6,%ebx
mov    $0x6,%edi
call   1050 <bar6@plt>
jmp    122d <foo+0x9d>
mov    $0x7,%ebx
mov    $0x7,%edi
call   10a0 <bar7@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @foo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %21 [
i32 0, label %5
i32 1, label %7
i32 2, label %9
i32 3, label %11
i32 4, label %13
i32 5, label %15
i32 6, label %17
i32 7, label %19
]
5: ; preds = %1
%6 = call i32 @bar0(i32 0)
store i32 0, i32* %2
br label %24
7: ; preds = %1
%8 = call i32 @bar1(i32 1)
store i32 1, i32* %2
br label %24
9: ; preds = %1
%10 = call i32 @bar2(i32 2)
store i32 2, i32* %2
br label %24
11: ; preds = %1
%12 = call i32 @bar3(i32 3)
store i32 3, i32* %2
br label %24
13: ; preds = %1
%14 = call i32 @bar4(i32 4)
store i32 4, i32* %2
br label %24
15: ; preds = %1
%16 = call i32 @bar5(i32 5)
store i32 5, i32* %2
br label %24
17: ; preds = %1
%18 = call i32 @bar6(i32 6)
store i32 6, i32* %2
br label %24
19: ; preds = %1
%20 = call i32 @bar7(i32 7)
store i32 7, i32* %2
br label %24
21: ; preds = %1
%22 = load i32, i32* %3
%23 = call i32 @bar(i32 %22)
store i32 %23, i32* %2
br label %24
24: ; preds = %21, %19, %17, %15, %13, %11, %9, %7, %5
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @foo(i32 %0) {
switch i32 %0, label %18 [
i32 0, label %2
i32 1, label %4
i32 2, label %6
i32 3, label %8
i32 4, label %10
i32 5, label %12
i32 6, label %14
i32 7, label %16
]
2: ; preds = %1
%3 = tail call i32 @bar0(i32 0)
br label %20
4: ; preds = %1
%5 = tail call i32 @bar1(i32 1)
br label %20
6: ; preds = %1
%7 = tail call i32 @bar2(i32 2)
br label %20
8: ; preds = %1
%9 = tail call i32 @bar3(i32 3)
br label %20
10: ; preds = %1
%11 = tail call i32 @bar4(i32 4)
br label %20
12: ; preds = %1
%13 = tail call i32 @bar5(i32 5)
br label %20
14: ; preds = %1
%15 = tail call i32 @bar6(i32 6)
br label %20
16: ; preds = %1
%17 = tail call i32 @bar7(i32 7)
br label %20
18: ; preds = %1
%19 = tail call i32 @bar(i32 %0)
br label %20
20: ; preds = %18, %16, %14, %12, %10, %8, %6, %4, %2
%21 = phi i32 [ %19, %18 ], [ 7, %16 ], [ 6, %14 ], [ 5, %12 ], [ 4, %10 ], [ 3, %8 ], [ 2, %6 ], [ 1, %4 ], [ 0, %2 ]
ret i32 %21
}