#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ proto;

/* Variables and functions */
#define IPPROTO_ICMP 132
#define IPPROTO_ICMPV6 131
#define IPPROTO_IGMP 130
#define IPPROTO_TCP 129
#define IPPROTO_UDP 128
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *ipproto_name(uint8_t proto_id) {
  static char proto[8];
  switch (proto_id) {
  case IPPROTO_TCP:
    return ("TCP");
    break;
  case IPPROTO_UDP:
    return ("UDP");
    break;
  case IPPROTO_ICMP:
    return ("ICMP");
    break;
  case IPPROTO_ICMPV6:
    return ("ICMPV6");
    break;
  case 112:
    return ("VRRP");
    break;
  case IPPROTO_IGMP:
    return ("IGMP");
    break;
  default:
    return ("UNKNOWN");
    break;
  }
  snprintf(proto, sizeof(proto), "%u", proto_id);
  return (proto);
}


x86 assembly (clang, -O0):
<ipproto_name>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff90,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x14,%eax
ja     1190 <ipproto_name+0x90>
mov    -0x18(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf1d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <ipproto_name+0x9b>
lea    0xf11(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <ipproto_name+0x9b>
lea    0xf05(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <ipproto_name+0x9b>
lea    0xefa(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <ipproto_name+0x9b>
lea    0xef1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <ipproto_name+0x9b>
lea    0xee6(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <ipproto_name+0x9b>
lea    0xedb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipproto_name>:
add    $0xffffff90,%edi
cmp    $0x14,%edi
ja     1127 <ipproto_name+0x27>
lea    0xf45(%rip),%rax
lea    0xeea(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xf42(%rip),%rax
ret
lea    0xf44(%rip),%rax
ret
lea    0xf22(%rip),%rax
ret
lea    0xf2f(%rip),%rax
ret
lea    0xf1b(%rip),%rax
ret
lea    0xf0e(%rip),%rax
ret

LLVM IR (-O0):
@ipproto_name.proto = internal global [8 x i8] zeroinitializer
@.str = [4 x i8] c"TCP\00"
@.str.1 = [4 x i8] c"UDP\00"
@.str.2 = [5 x i8] c"ICMP\00"
@.str.3 = [7 x i8] c"ICMPV6\00"
@.str.4 = [5 x i8] c"VRRP\00"
@.str.5 = [5 x i8] c"IGMP\00"
@.str.6 = [8 x i8] c"UNKNOWN\00"
define i8* @ipproto_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %11 [
i32 129, label %5
i32 128, label %6
i32 132, label %7
i32 131, label %8
i32 112, label %9
i32 130, label %10
]
5: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %2
br label %12
6: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %12
7: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %12
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %12
9: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %12
10: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %12
11: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %12
12: ; preds = %11, %10, %9, %8, %7, %6, %5
%13 = load i8*, i8** %2
ret i8* %13
}

LLVM IR (-O2):
@.str = [4 x i8] c"TCP\00"
@.str.1 = [4 x i8] c"UDP\00"
@.str.2 = [5 x i8] c"ICMP\00"
@.str.3 = [7 x i8] c"ICMPV6\00"
@.str.4 = [5 x i8] c"VRRP\00"
@.str.5 = [5 x i8] c"IGMP\00"
@.str.6 = [8 x i8] c"UNKNOWN\00"
define i8* @ipproto_name(i32 %0) {
switch i32 %0, label %7 [
i32 129, label %8
i32 128, label %2
i32 132, label %3
i32 131, label %4
i32 112, label %5
i32 130, label %6
]
2: ; preds = %1
br label %8
3: ; preds = %1
br label %8
4: ; preds = %1
br label %8
5: ; preds = %1
br label %8
6: ; preds = %1
br label %8
7: ; preds = %1
br label %8
8: ; preds = %1, %7, %6, %5, %4, %3, %2
%9 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %7 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %9
}