#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 ihl;
  int /*<<< orphan*/ protocol;
};
struct __sk_buff {
  int dummy;
};
typedef int /*<<< orphan*/ iph_outer;

/* Variables and functions */
int /*<<< orphan*/ ETH_HLEN;
int TC_ACT_OK;
scalar_t__ bpf_skb_load_bytes(struct __sk_buff *, int /*<<< orphan*/,
                              struct iphdr *, int);
int decap_internal(struct __sk_buff *, int /*<<< orphan*/, int,
                   int /*<<< orphan*/);
int decap_ipv4(struct __sk_buff *skb) {
  struct iphdr iph_outer;
  if (bpf_skb_load_bytes(skb, ETH_HLEN, &iph_outer, sizeof(iph_outer)) < 0)
    return TC_ACT_OK;
  if (iph_outer.ihl != 5)
    return TC_ACT_OK;
  return decap_internal(skb, ETH_HLEN, sizeof(iph_outer), iph_outer.protocol);
}


x86 assembly (clang, -O0):
<decap_ipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
mov    $0x8,%ecx
call   1040 <bpf_skb_load_bytes@plt>
cmp    $0x0,%rax
jge    1162 <decap_ipv4+0x42>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <decap_ipv4+0x7a>
cmpl   $0x5,-0x18(%rbp)
je     117d <decap_ipv4+0x5d>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <decap_ipv4+0x7a>
mov    -0x10(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%ecx
mov    $0x8,%edx
call   1030 <decap_internal@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decap_ipv4>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eaa(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rdx
mov    $0x8,%ecx
call   1040 <bpf_skb_load_bytes@plt>
test   %rax,%rax
js     115f <decap_ipv4+0x3f>
cmpl   $0x5,(%rsp)
jne    115f <decap_ipv4+0x3f>
mov    (%r14),%esi
mov    0x4(%rsp),%ecx
mov    %rbx,%rdi
mov    $0x8,%edx
call   1030 <decap_internal@plt>
jmp    1168 <decap_ipv4+0x48>
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i32 }
%struct.iphdr = type { i32, i32 }
@ETH_HLEN = global i32 0
@TC_ACT_OK = global i32 0
define i32 @decap_ipv4(%struct.__sk_buff* %0) {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
%4 = alloca %struct.iphdr
store %struct.__sk_buff* %0, %struct.__sk_buff** %3
%5 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%6 = load i32, i32* @ETH_HLEN
%7 = call i64 @bpf_skb_load_bytes(%struct.__sk_buff* %5, i32 %6, %struct.iphdr* %4, i32 8)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i32, i32* @TC_ACT_OK
store i32 %10, i32* %2
br label %23
11: ; preds = %1
%12 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp ne i32 %13, 5
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32, i32* @TC_ACT_OK
store i32 %16, i32* %2
br label %23
17: ; preds = %11
%18 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%19 = load i32, i32* @ETH_HLEN
%20 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %4, i32 0, i32 1
%21 = load i32, i32* %20
%22 = call i32 @decap_internal(%struct.__sk_buff* %18, i32 %19, i32 8, i32 %21)
store i32 %22, i32* %2
br label %23
23: ; preds = %17, %15, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.__sk_buff = type { i32 }
%struct.iphdr = type { i32, i32 }
@ETH_HLEN = global i32 0
@TC_ACT_OK = global i32 0
define i32 @decap_ipv4(%struct.__sk_buff* %0) {
%2 = alloca %struct.iphdr
%3 = bitcast %struct.iphdr* %2 to i8*
%4 = load i32, i32* @ETH_HLEN
%5 = call i64 @bpf_skb_load_bytes(%struct.__sk_buff* %0, i32 %4, %struct.iphdr* %2, i32 8)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* @TC_ACT_OK
br label %20
9: ; preds = %1
%10 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 5
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = load i32, i32* @TC_ACT_OK
br label %20
15: ; preds = %9
%16 = load i32, i32* @ETH_HLEN
%17 = getelementptr inbounds %struct.iphdr, %struct.iphdr* %2, i64 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 @decap_internal(%struct.__sk_buff* %0, i32 %16, i32 8, i32 %18)
br label %20
20: ; preds = %15, %13, %7
%21 = phi i32 [ %8, %7 ], [ %14, %13 ], [ %19, %15 ]
ret i32 %21
}