#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;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
void convert_ipv4_type(const uint8_t opcode, char *ipv4_type) {
  switch (opcode) {
  case 1:
    snprintf((char *)ipv4_type, 8, "ICMP");
    break;
  case 2:
    snprintf((char *)ipv4_type, 8, "IGMP");
    break;
  case 6:
    snprintf((char *)ipv4_type, 8, "TCP");
    break;
  case 17:
    snprintf((char *)ipv4_type, 8, "UDP");
    break;
  default:
    snprintf((char *)ipv4_type, 8, "%d ??", opcode);
    break;
  }
}


x86 assembly (clang, -O0):
<convert_ipv4_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x10,%eax
ja     11b8 <convert_ipv4_type+0xa8>
mov    -0x18(%rbp),%rax
lea    0xec1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
lea    0xeec(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11d2 <convert_ipv4_type+0xc2>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
lea    0xed5(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11d2 <convert_ipv4_type+0xc2>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
lea    0xebe(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11d2 <convert_ipv4_type+0xc2>
mov    -0x10(%rbp),%rdi
mov    $0x8,%esi
lea    0xea6(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11d2 <convert_ipv4_type+0xc2>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x8,%esi
lea    0xe8b(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_ipv4_type>:
mov    %edi,%ecx
lea    -0x1(%rcx),%eax
cmp    $0x10,%eax
ja     113c <convert_ipv4_type+0x2c>
lea    0xedf(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
lea    0xf13(%rip),%rdx
jmp    1162 <convert_ipv4_type+0x52>
lea    0xf0f(%rip),%rdx
jmp    1162 <convert_ipv4_type+0x52>
lea    0xf13(%rip),%rdx
mov    %rsi,%rdi
mov    $0x8,%esi
xor    %eax,%eax
jmp    1030 <snprintf@plt>
lea    0xef5(%rip),%rdx
jmp    1162 <convert_ipv4_type+0x52>
lea    0xef0(%rip),%rdx
mov    %rsi,%rdi
mov    $0x8,%esi
xor    %eax,%eax
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"ICMP\00"
@.str.1 = [5 x i8] c"IGMP\00"
@.str.2 = [4 x i8] c"TCP\00"
@.str.3 = [4 x i8] c"UDP\00"
@.str.4 = [6 x i8] c"%d ??\00"
define void @convert_ipv4_type(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
switch i32 %5, label %18 [
i32 1, label %6
i32 2, label %9
i32 6, label %12
i32 17, label %15
]
6: ; preds = %2
%7 = load i8*, i8** %4
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %10, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %22
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %16, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %22
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %19, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"ICMP\00"
@.str.1 = [5 x i8] c"IGMP\00"
@.str.2 = [4 x i8] c"TCP\00"
@.str.3 = [4 x i8] c"UDP\00"
@.str.4 = [6 x i8] c"%d ??\00"
define void @convert_ipv4_type(i32 %0, i8* %1) {
switch i32 %0, label %11 [
i32 1, label %3
i32 2, label %5
i32 6, label %7
i32 17, label %9
]
3: ; preds = %2
%4 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
5: ; preds = %2
%6 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
7: ; preds = %2
%8 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %13
9: ; preds = %2
%10 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %13
11: ; preds = %2
%12 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %1, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %11, %9, %7, %5, %3
ret void
}