#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 */
struct iphdr {
  int protocol;
};
struct ethhdr {
  int dummy;
};

/* Variables and functions */
#define IPPROTO_ICMP 130
#define IPPROTO_TCP 129
#define IPPROTO_UDP 128
int /*<<< orphan*/ ip_icmp_packet_callback(char *, int);
int /*<<< orphan*/ ip_tcp_packet_callback(char *, int);
int /*<<< orphan*/ ip_udp_packet_callback(char *, int);
void ip_packet_callback(char *packet_content, int size) {
  struct iphdr *iph;
  iph = (struct iphdr *)(packet_content + sizeof(struct ethhdr));
  switch (iph->protocol) {
  case IPPROTO_ICMP:
    ip_icmp_packet_callback(packet_content, size);
    break;
  case IPPROTO_TCP:
    ip_tcp_packet_callback(packet_content, size);
    break;
  case IPPROTO_UDP:
    ip_udp_packet_callback(packet_content, size);
    break;
  }
}


x86 assembly (clang, -O0):
<ip_packet_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     11ac <ip_packet_callback+0x7c>
jmp    1164 <ip_packet_callback+0x34>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
je     119b <ip_packet_callback+0x6b>
jmp    1177 <ip_packet_callback+0x47>
mov    -0x1c(%rbp),%eax
sub    $0x82,%eax
jne    11b8 <ip_packet_callback+0x88>
jmp    118a <ip_packet_callback+0x5a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <ip_icmp_packet_callback@plt>
jmp    11b8 <ip_packet_callback+0x88>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <ip_tcp_packet_callback@plt>
jmp    11b8 <ip_packet_callback+0x88>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <ip_udp_packet_callback@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_packet_callback>:
mov    0x4(%rdi),%eax
cmp    $0x80,%eax
je     114d <ip_packet_callback+0x1d>
cmp    $0x81,%eax
je     1152 <ip_packet_callback+0x22>
cmp    $0x82,%eax
jne    1157 <ip_packet_callback+0x27>
jmp    1050 <ip_icmp_packet_callback@plt>
jmp    1030 <ip_udp_packet_callback@plt>
jmp    1040 <ip_tcp_packet_callback@plt>
ret

LLVM IR (-O0):
%struct.iphdr = type { i32 }
define void @ip_packet_callback(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.iphdr*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 4
%8 = bitcast i8* %7 to %struct.iphdr*
store %struct.iphdr* %8, %struct.iphdr** %5
%9 = load %struct.iphdr*, %struct.iphdr** %5
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %9, i32 0, i32 0
%11 = load i32, i32* %10
switch i32 %11, label %24 [
i32 130, label %12
i32 129, label %16
i32 128, label %20
]
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = call i32 @ip_icmp_packet_callback(i8* %13, i32 %14)
br label %24
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = call i32 @ip_tcp_packet_callback(i8* %17, i32 %18)
br label %24
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load i32, i32* %4
%23 = call i32 @ip_udp_packet_callback(i8* %21, i32 %22)
br label %24
24: ; preds = %2, %20, %16, %12
ret void
}

LLVM IR (-O2):
define void @ip_packet_callback(i8* %0, i32 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = bitcast i8* %3 to i32*
%5 = load i32, i32* %4
switch i32 %5, label %12 [
i32 130, label %6
i32 129, label %8
i32 128, label %10
]
6: ; preds = %2
%7 = tail call i32 @ip_icmp_packet_callback(i8* %0, i32 %1)
br label %12
8: ; preds = %2
%9 = tail call i32 @ip_tcp_packet_callback(i8* %0, i32 %1)
br label %12
10: ; preds = %2
%11 = tail call i32 @ip_udp_packet_callback(i8* %0, i32 %1)
br label %12
12: ; preds = %2, %10, %8, %6
ret void
}