#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 */
#define ETHERTYPE_ARP 130
#define ETHERTYPE_IP 129
#define ETHERTYPE_IPV6 128
const char *get_ether_type(unsigned short type) {
  switch (type) {
  case ETHERTYPE_IP:
    return "IPv4";
  case ETHERTYPE_IPV6:
    return "IPv6";
  case ETHERTYPE_ARP:
    return "ARP";
  }
  return "Unknown";
}


x86 assembly (clang, -O0):
<get_ether_type>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x80,%eax
je     1158 <get_ether_type+0x58>
jmp    1122 <get_ether_type+0x22>
mov    -0x10(%rbp),%eax
sub    $0x81,%eax
je     1148 <get_ether_type+0x48>
jmp    1135 <get_ether_type+0x35>
mov    -0x10(%rbp),%eax
sub    $0x82,%eax
je     1168 <get_ether_type+0x68>
jmp    1178 <get_ether_type+0x78>
lea    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <get_ether_type+0x83>
lea    0xea6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <get_ether_type+0x83>
lea    0xe9b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1183 <get_ether_type+0x83>
lea    0xe8f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ether_type>:
add    $0xffffff80,%edi
cmp    $0x2,%di
ja     111c <get_ether_type+0x1c>
movswq %di,%rax
lea    0xf04(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xeeb(%rip),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"IPv4\00"
@.str.1 = [5 x i8] c"IPv6\00"
@.str.2 = [4 x i8] c"ARP\00"
@.str.3 = [8 x i8] c"Unknown\00"
define i8* @get_ether_type(i16 zeroext %0) {
%2 = alloca i8*
%3 = alloca i16
store i16 %0, i16* %3
%4 = load i16, i16* %3
%5 = zext i16 %4 to i32
switch i32 %5, label %9 [
i32 129, label %6
i32 128, label %7
i32 130, label %8
]
6: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
br label %10
7: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %10
8: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %10
9: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %10
10: ; preds = %9, %8, %7, %6
%11 = load i8*, i8** %2
ret i8* %11
}

LLVM IR (-O2):
@.str = [5 x i8] c"IPv4\00"
@.str.1 = [5 x i8] c"IPv6\00"
@.str.2 = [4 x i8] c"ARP\00"
@.str.3 = [8 x i8] c"Unknown\00"
@reltable.get_ether_type = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.get_ether_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.get_ether_type to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.get_ether_type to i64)) to i32)]
define i8* @get_ether_type(i16 zeroext %0) {
%2 = add i16 %0, -128
%3 = icmp ult i16 %2, 3
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i16 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.get_ether_type to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %1 ]
ret i8* %9
}