#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 */
scalar_t__ bar();
scalar_t__ baz();
scalar_t__ foo();
scalar_t__ fooz();
int caller(unsigned int reg_type) {
  switch (reg_type) {
  case 0x80000000:
    return (int)foo();
  case 0x80000003:
    return (int)bar();
  case 0x80000001:
    return (int)baz();
  case 0x80000004:
    return (int)fooz();
  }
}


x86 assembly (clang, -O0):
<caller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x80000000,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x4,%eax
ja     11ad <caller+0x6d>
mov    -0x10(%rbp),%rax
lea    0xe93(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1060 <foo@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <caller+0x6d>
mov    $0x0,%al
call   1040 <bar@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <caller+0x6d>
mov    $0x0,%al
call   1030 <baz@plt>
mov    %eax,-0x4(%rbp)
jmp    11ad <caller+0x6d>
mov    $0x0,%al
call   1050 <fooz@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<caller>:
push   %rax
add    $0x80000000,%edi
cmp    $0x4,%edi
ja     1163 <caller+0x23>
lea    0xead(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
call   1060 <foo@plt>
pop    %rcx
ret
xor    %eax,%eax
call   1030 <baz@plt>
pop    %rcx
ret
xor    %eax,%eax
call   1040 <bar@plt>
pop    %rcx
ret
xor    %eax,%eax
call   1050 <fooz@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @caller(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %17 [
i32 -2147483648, label %5
i32 -2147483645, label %8
i32 -2147483647, label %11
i32 -2147483644, label %14
]
5: ; preds = %1
%6 = call i64 (...) @foo()
%7 = trunc i64 %6 to i32
store i32 %7, i32* %2
br label %17
8: ; preds = %1
%9 = call i64 (...) @bar()
%10 = trunc i64 %9 to i32
store i32 %10, i32* %2
br label %17
11: ; preds = %1
%12 = call i64 (...) @baz()
%13 = trunc i64 %12 to i32
store i32 %13, i32* %2
br label %17
14: ; preds = %1
%15 = call i64 (...) @fooz()
%16 = trunc i64 %15 to i32
store i32 %16, i32* %2
br label %17
17: ; preds = %5, %8, %11, %14, %1
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
define i32 @caller(i32 %0) {
switch i32 %0, label %14 [
i32 -2147483648, label %2
i32 -2147483645, label %5
i32 -2147483647, label %8
i32 -2147483644, label %11
]
2: ; preds = %1
%3 = tail call i64 (...) @foo()
%4 = trunc i64 %3 to i32
br label %14
5: ; preds = %1
%6 = tail call i64 (...) @bar()
%7 = trunc i64 %6 to i32
br label %14
8: ; preds = %1
%9 = tail call i64 (...) @baz()
%10 = trunc i64 %9 to i32
br label %14
11: ; preds = %1
%12 = tail call i64 (...) @fooz()
%13 = trunc i64 %12 to i32
br label %14
14: ; preds = %2, %5, %8, %11, %1
%15 = phi i32 [ undef, %1 ], [ %13, %11 ], [ %10, %8 ], [ %7, %5 ], [ %4, %2 ]
ret i32 %15
}