#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 */
char const *fmt_ethertype(unsigned short ethertype) {
  switch (ethertype) {
  case 0x0800:
    return "ETH_P_IP";
  case 0x86DD:
    return "ETH_P_IPV6";
  case 0x0806:
    return "ETH_P_ARP";
  case 0x88CC:
    return "ETH_P_LLDP";
  case 0x8100:
    return "ETH_P_VLAN";
  default:
    return NULL;
  }
}


x86 assembly (clang, -O0):
<fmt_ethertype>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x800,%eax
je     116e <fmt_ethertype+0x6e>
jmp    1122 <fmt_ethertype+0x22>
mov    -0x10(%rbp),%eax
sub    $0x806,%eax
je     118e <fmt_ethertype+0x8e>
jmp    1135 <fmt_ethertype+0x35>
mov    -0x10(%rbp),%eax
sub    $0x8100,%eax
je     11ae <fmt_ethertype+0xae>
jmp    1148 <fmt_ethertype+0x48>
mov    -0x10(%rbp),%eax
sub    $0x86dd,%eax
je     117e <fmt_ethertype+0x7e>
jmp    115b <fmt_ethertype+0x5b>
mov    -0x10(%rbp),%eax
sub    $0x88cc,%eax
je     119e <fmt_ethertype+0x9e>
jmp    11be <fmt_ethertype+0xbe>
lea    0xe8b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <fmt_ethertype+0xc6>
lea    0xe84(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <fmt_ethertype+0xc6>
lea    0xe7f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <fmt_ethertype+0xc6>
lea    0xe79(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <fmt_ethertype+0xc6>
lea    0xe74(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c6 <fmt_ethertype+0xc6>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fmt_ethertype>:
movswl %di,%ecx
movzwl %cx,%eax
cmp    $0xffff88cb,%ecx
jle    112b <fmt_ethertype+0x2b>
cmp    $0x88cc,%eax
je     1141 <fmt_ethertype+0x41>
cmp    $0x800,%eax
je     1149 <fmt_ethertype+0x49>
cmp    $0x806,%eax
jne    1159 <fmt_ethertype+0x59>
lea    0xeea(%rip),%rax
ret
cmp    $0x8100,%eax
je     1151 <fmt_ethertype+0x51>
cmp    $0x86dd,%eax
jne    1159 <fmt_ethertype+0x59>
lea    0xec9(%rip),%rax
ret
lea    0xed6(%rip),%rax
ret
lea    0xeb0(%rip),%rax
ret
lea    0xed1(%rip),%rax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [9 x i8] c"ETH_P_IP\00"
@.str.1 = [11 x i8] c"ETH_P_IPV6\00"
@.str.2 = [10 x i8] c"ETH_P_ARP\00"
@.str.3 = [11 x i8] c"ETH_P_LLDP\00"
@.str.4 = [11 x i8] c"ETH_P_VLAN\00"
define i8* @fmt_ethertype(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 %11 [
i32 2048, label %6
i32 34525, label %7
i32 2054, label %8
i32 35020, label %9
i32 33024, label %10
]
6: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
br label %12
7: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %12
8: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %12
9: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %12
10: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %12
11: ; preds = %1
store i8* null, i8** %2
br label %12
12: ; preds = %11, %10, %9, %8, %7, %6
%13 = load i8*, i8** %2
ret i8* %13
}

LLVM IR (-O2):
@.str = [9 x i8] c"ETH_P_IP\00"
@.str.1 = [11 x i8] c"ETH_P_IPV6\00"
@.str.2 = [10 x i8] c"ETH_P_ARP\00"
@.str.3 = [11 x i8] c"ETH_P_LLDP\00"
@.str.4 = [11 x i8] c"ETH_P_VLAN\00"
define i8* @fmt_ethertype(i16 zeroext %0) {
switch i16 %0, label %6 [
i16 2048, label %7
i16 -31011, label %2
i16 2054, label %3
i16 -30516, label %4
i16 -32512, label %5
]
2: ; preds = %1
br label %7
3: ; preds = %1
br label %7
4: ; preds = %1
br label %7
5: ; preds = %1
br label %7
6: ; preds = %1
br label %7
7: ; preds = %1, %6, %5, %4, %3, %2
%8 = phi i8* [ null, %6 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %8
}