#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 ipv6hdr {
  int /*<<< orphan*/ nexthdr;
};
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 ipv6hdr *, int);
int decap_internal(struct __sk_buff *, int /*<<< orphan*/, int,
                   int /*<<< orphan*/);
int decap_ipv6(struct __sk_buff *skb) {
  struct ipv6hdr iph_outer;
  if (bpf_skb_load_bytes(skb, ETH_HLEN, &iph_outer, sizeof(iph_outer)) < 0)
    return TC_ACT_OK;
  return decap_internal(skb, ETH_HLEN, sizeof(iph_outer), iph_outer.nexthdr);
}


x86 assembly (clang, -O0):
<decap_ipv6>:
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    $0x4,%ecx
call   1040 <bpf_skb_load_bytes@plt>
cmp    $0x0,%rax
jge    1162 <decap_ipv6+0x42>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    117f <decap_ipv6+0x5f>
mov    -0x10(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%ecx
mov    $0x4,%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_ipv6>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2eaa(%rip),%r14
mov    (%r14),%esi
mov    %rsp,%rdx
mov    $0x4,%ecx
call   1040 <bpf_skb_load_bytes@plt>
test   %rax,%rax
js     1158 <decap_ipv6+0x38>
mov    (%r14),%esi
mov    (%rsp),%ecx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <decap_internal@plt>
jmp    1161 <decap_ipv6+0x41>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i32 }
%struct.ipv6hdr = type { i32 }
@ETH_HLEN = global i32 0
@TC_ACT_OK = global i32 0
define i32 @decap_ipv6(%struct.__sk_buff* %0) {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
%4 = alloca %struct.ipv6hdr
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.ipv6hdr* %4, i32 4)
%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 %17
11: ; preds = %1
%12 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%13 = load i32, i32* @ETH_HLEN
%14 = getelementptr inbounds %struct.ipv6hdr, %struct.ipv6hdr* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @decap_internal(%struct.__sk_buff* %12, i32 %13, i32 4, i32 %15)
store i32 %16, i32* %2
br label %17
17: ; preds = %11, %9
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.__sk_buff = type { i32 }
%struct.ipv6hdr = type { i32 }
@ETH_HLEN = global i32 0
@TC_ACT_OK = global i32 0
define i32 @decap_ipv6(%struct.__sk_buff* %0) {
%2 = alloca %struct.ipv6hdr
%3 = bitcast %struct.ipv6hdr* %2 to i8*
%4 = load i32, i32* @ETH_HLEN
%5 = call i64 @bpf_skb_load_bytes(%struct.__sk_buff* %0, i32 %4, %struct.ipv6hdr* %2, i32 4)
%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 %14
9: ; preds = %1
%10 = load i32, i32* @ETH_HLEN
%11 = getelementptr inbounds %struct.ipv6hdr, %struct.ipv6hdr* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @decap_internal(%struct.__sk_buff* %0, i32 %10, i32 4, i32 %12)
br label %14
14: ; preds = %9, %7
%15 = phi i32 [ %8, %7 ], [ %13, %9 ]
ret i32 %15
}