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

/* Variables and functions */
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, ...);
__attribute__((section("ipip_get_tunnel"), used)) int
_ipip_get_tunnel(struct __sk_buff *skb) {
  int ret;
  struct bpf_tunnel_key key;
  char fmt[] = "remote ip 0x%x\n";
  ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
  if (ret < 0) {
    do {
      char fmt[] = "ERROR line:%d ret:%d\n";
      bpf_trace_printk(fmt, sizeof(fmt), 574, ret);
    } while (0);
    return TC_ACT_SHOT;
  }
  bpf_trace_printk(fmt, sizeof(fmt), key.remote_ipv4);
  return TC_ACT_OK;
}


x86 assembly (clang, -O0):
<_ipip_get_tunnel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <bpf_skb_get_tunnel_key@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11bb <_ipip_get_tunnel+0x9b>
jmp    1168 <_ipip_get_tunnel+0x48>
mov    0xea1(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe9c(%rip),%eax
mov    %eax,-0x40(%rbp)
mov    0xe96(%rip),%ax
mov    %ax,-0x3c(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x16,%esi
mov    $0x23e,%edx
mov    $0x0,%al
call   1040 <bpf_trace_printk@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11da <_ipip_get_tunnel+0xba>
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%edx
mov    $0x10,%esi
mov    $0x0,%al
call   1040 <bpf_trace_printk@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ipip_get_tunnel>:
sub    $0x48,%rsp
movaps 0xed5(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1030 <bpf_skb_get_tunnel_key@plt>
test   %eax,%eax
js     1163 <_ipip_get_tunnel+0x43>
mov    0x8(%rsp),%edx
lea    0x30(%rsp),%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1040 <bpf_trace_printk@plt>
mov    0x2e7f(%rip),%rax
jmp    119d <_ipip_get_tunnel+0x7d>
movaps 0xea6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0xa64253a746572,%rcx
mov    %rcx,0x1e(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x16,%esi
mov    $0x23e,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <bpf_trace_printk@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i32 }
%struct.bpf_tunnel_key = type { i32 }
@__const._ipip_get_tunnel.fmt = [16 x i8] c"remote ip 0x%x\0A\00"
@__const._ipip_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*)* @_ipip_get_tunnel to i8*)], section "llvm.metadata"
define i32 @_ipip_get_tunnel(%struct.__sk_buff* %0) section "ipip_get_tunnel" {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
%4 = alloca i32
%5 = alloca %struct.bpf_tunnel_key
%6 = alloca [16 x i8]
%7 = alloca [22 x i8]
store %struct.__sk_buff* %0, %struct.__sk_buff** %3
%8 = bitcast [16 x i8]* %6 to i8*
%9 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%10 = call i32 @bpf_skb_get_tunnel_key(%struct.__sk_buff* %9, %struct.bpf_tunnel_key* %5, i32 4, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %1
br label %14
14: ; preds = %13
%15 = bitcast [22 x i8]* %7 to i8*
%16 = getelementptr inbounds [22 x i8], [22 x i8]* %7, i64 0, i64 0
%17 = load i32, i32* %4
%18 = call i32 (i8*, i32, i32, ...) @bpf_trace_printk(i8* %16, i32 22, i32 574, i32 %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* @TC_ACT_SHOT
store i32 %20, i32* %2
br label %27
21: ; preds = %1
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%23 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %5, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 (i8*, i32, i32, ...) @bpf_trace_printk(i8* %22, i32 16, i32 %24)
%26 = load i32, i32* @TC_ACT_OK
store i32 %26, i32* %2
br label %27
27: ; preds = %21, %19
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
%struct.__sk_buff = type { i32 }
%struct.bpf_tunnel_key = type { i32 }
@__const._ipip_get_tunnel.fmt = [16 x i8] c"remote ip 0x%x\0A\00"
@__const._ipip_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*)* @_ipip_get_tunnel to i8*)], section "llvm.metadata"
define i32 @_ipip_get_tunnel(%struct.__sk_buff* %0) section "ipip_get_tunnel" {
%2 = alloca %struct.bpf_tunnel_key
%3 = alloca [16 x i8]
%4 = alloca [22 x i8]
%5 = bitcast %struct.bpf_tunnel_key* %2 to i8*
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%7 = call i32 @bpf_skb_get_tunnel_key(%struct.__sk_buff* %0, %struct.bpf_tunnel_key* %2, i32 4, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = getelementptr inbounds [22 x i8], [22 x i8]* %4, i64 0, i64 0
%11 = call i32 (i8*, i32, i32, ...) @bpf_trace_printk(i8* %10, i32 22, i32 574, i32 %7)
br label %16
12: ; preds = %1
%13 = getelementptr inbounds %struct.bpf_tunnel_key, %struct.bpf_tunnel_key* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 (i8*, i32, i32, ...) @bpf_trace_printk(i8* %6, i32 16, i32 %14)
br label %16
16: ; preds = %12, %9
%17 = phi i32* [ @TC_ACT_SHOT, %9 ], [ @TC_ACT_OK, %12 ]
%18 = load i32, i32* %17
ret i32 %18
}