#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 bpf_tunnel_key {
  int /*<<< orphan*/ tunnel_label;
  int /*<<< orphan*/ *remote_ipv6;
  int /*<<< orphan*/ tunnel_id;
};
struct __sk_buff {
  int dummy;
};
typedef int /*<<< orphan*/ key;
typedef int /*<<< orphan*/ fmt;

/* Variables and functions */
int /*<<< orphan*/ BPF_F_TUNINFO_IPV6;
int TC_ACT_OK;
int TC_ACT_SHOT;
int bpf_skb_get_tunnel_key(struct __sk_buff *, struct bpf_tunnel_key *, int,
                           int /*<<< orphan*/);
int /*<<< orphan*/ bpf_trace_printk(char *, int, int, int, ...);
__attribute__((section("ip6gretap_get_tunnel"), used)) int
_ip6gretap_get_tunnel(struct __sk_buff *skb) {
  char fmt[] = "key %d remote ip6 ::%x label %x\n";
  struct bpf_tunnel_key key;
  int ret;
  ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), BPF_F_TUNINFO_IPV6);
  if (ret < 0) {
    do {
      char fmt[] = "ERROR line:%d ret:%d\n";
      bpf_trace_printk(fmt, sizeof(fmt), 119, ret);
    } while (0);
    return TC_ACT_SHOT;
  }
  bpf_trace_printk(fmt, sizeof(fmt), key.tunnel_id, key.remote_ipv6[3],
                   key.tunnel_label);
  return TC_ACT_OK;
}


x86 assembly (clang, -O0):
<_ip6gretap_get_tunnel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x21,%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%ecx
lea    -0x58(%rbp),%rsi
mov    $0x18,%edx
call   1040 <bpf_skb_get_tunnel_key@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    11d4 <_ip6gretap_get_tunnel+0xa4>
jmp    1181 <_ip6gretap_get_tunnel+0x51>
mov    0xea8(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xea3(%rip),%eax
mov    %eax,-0x70(%rbp)
mov    0xe9d(%rip),%ax
mov    %ax,-0x6c(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x5c(%rbp),%ecx
mov    $0x16,%esi
mov    $0x77,%edx
mov    $0x0,%al
call   1050 <bpf_trace_printk@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fe <_ip6gretap_get_tunnel+0xce>
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%edx
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x58(%rbp),%r8d
mov    $0x21,%esi
mov    $0x0,%al
call   1050 <bpf_trace_printk@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ip6gretap_get_tunnel>:
sub    $0x68,%rsp
movaps 0xee5(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xec9(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movb   $0x0,0x60(%rsp)
mov    0x2e88(%rip),%rax
mov    (%rax),%ecx
lea    0x8(%rsp),%rsi
mov    $0x18,%edx
call   1030 <bpf_skb_get_tunnel_key@plt>
test   %eax,%eax
js     1188 <_ip6gretap_get_tunnel+0x68>
mov    0x18(%rsp),%edx
mov    0x10(%rsp),%rax
mov    0xc(%rax),%ecx
mov    0x8(%rsp),%r8d
lea    0x40(%rsp),%rdi
mov    $0x21,%esi
xor    %eax,%eax
call   1040 <bpf_trace_printk@plt>
mov    0x2e5a(%rip),%rax
jmp    11c2 <_ip6gretap_get_tunnel+0xa2>
movaps 0xea1(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movabs $0xa64253a746572,%rcx
mov    %rcx,0x2e(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x16,%esi
mov    $0x77,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <bpf_trace_printk@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
add    $0x68,%rsp
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i32 }
%struct.bpf_tunnel_key = type { i32, i32*, i32 }
@__const._ip6gretap_get_tunnel.fmt = [33 x i8] c"key %d remote ip6 ::%x label %x\0A\00"
@BPF_F_TUNINFO_IPV6 = global i32 0
@__const._ip6gretap_get_tunnel.fmt.1 = [22 x i8] c"ERROR line:%d ret:%d\0A\00"
@TC_ACT_SHOT = global i32 0
@TC_ACT_OK = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @_ip6gretap_get_tunnel to i8*)], section "llvm.metadata"
define i32 @_ip6gretap_get_tunnel(%struct.__sk_buff* %0) section "ip6gretap_get_tunnel" {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
%4 = alloca [33 x i8]
%5 = alloca %struct.bpf_tunnel_key
%6 = alloca i32
%7 = alloca [22 x i8]
store %struct.__sk_buff* %0, %struct.__sk_buff** %3
%8 = bitcast [33 x i8]* %4 to i8*
%9 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%10 = load i32, i32* @BPF_F_TUNINFO_IPV6
%11 = call i32 @bpf_skb_get_tunnel_key(%struct.__sk_buff* %9, %struct.bpf_tunnel_key* %5, i32 24, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %1
br label %15
15: ; preds = %14
%16 = bitcast [22 x i8]* %7 to i8*
%17 = getelementptr inbounds [22 x i8], [22 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %6
%19 = call i32 (i8*, i32, i32, i32, ...) @bpf_trace_printk(i8* %17, i32 22, i32 119, i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* @TC_ACT_SHOT
store i32 %21, i32* %2
br label %34
22: ; preds = %1
%23 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %5, i32 0, i32 2
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %5, i32 0, i32 1
%27 = load i32*, i32** %26
%28 = getelementptr inbounds i32, i32* %27, i64 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %5, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 (i8*, i32, i32, i32, ...) @bpf_trace_printk(i8* %23, i32 33, i32 %25, i32 %29, i32 %31)
%33 = load i32, i32* @TC_ACT_OK
store i32 %33, i32* %2
br label %34
34: ; preds = %22, %20
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
%struct.__sk_buff = type { i32 }
%struct.bpf_tunnel_key = type { i32, i32*, i32 }
@__const._ip6gretap_get_tunnel.fmt = [33 x i8] c"key %d remote ip6 ::%x label %x\0A\00"
@BPF_F_TUNINFO_IPV6 = global i32 0
@__const._ip6gretap_get_tunnel.fmt.1 = [22 x i8] c"ERROR line:%d ret:%d\0A\00"
@TC_ACT_SHOT = global i32 0
@TC_ACT_OK = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @_ip6gretap_get_tunnel to i8*)], section "llvm.metadata"
define i32 @_ip6gretap_get_tunnel(%struct.__sk_buff* %0) section "ip6gretap_get_tunnel" {
%2 = alloca [33 x i8]
%3 = alloca %struct.bpf_tunnel_key
%4 = alloca [22 x i8]
%5 = getelementptr inbounds [33 x i8], [33 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.bpf_tunnel_key* %3 to i8*
%7 = load i32, i32* @BPF_F_TUNINFO_IPV6
%8 = call i32 @bpf_skb_get_tunnel_key(%struct.__sk_buff* %0, %struct.bpf_tunnel_key* %3, i32 24, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = getelementptr inbounds [22 x i8], [22 x i8]* %4, i64 0, i64 0
%12 = call i32 (i8*, i32, i32, i32, ...) @bpf_trace_printk(i8* %11, i32 22, i32 119, i32 %8)
br label %23
13: ; preds = %1
%14 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %3, i64 0, i32 2
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %3, i64 0, i32 1
%17 = load i32*, i32** %16
%18 = getelementptr inbounds i32, i32* %17, i64 3
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 (i8*, i32, i32, i32, ...) @bpf_trace_printk(i8* %5, i32 33, i32 %15, i32 %19, i32 %21)
br label %23
23: ; preds = %13, %10
%24 = phi i32* [ @TC_ACT_SHOT, %10 ], [ @TC_ACT_OK, %13 ]
%25 = load i32, i32* %24
ret i32 %25
}