#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 mpls_label {
  int dummy;
};
struct bpf_flow_keys {
  int dummy;
};
struct __sk_buff {
  struct bpf_flow_keys *flow_keys;
};

/* Variables and functions */
int /*<<< orphan*/ BPF_DROP;
int /*<<< orphan*/ BPF_OK;
struct mpls_label *bpf_flow_dissect_get_header(struct __sk_buff *, int,
                                               struct mpls_label *);
int export_flow_keys(struct bpf_flow_keys *, int /*<<< orphan*/);
__attribute__((section("MPLS"), used)) int
bpf_func_MPLS(struct __sk_buff *skb) {
  struct bpf_flow_keys *keys = skb->flow_keys;
  struct mpls_label *mpls, _mpls;
  mpls = bpf_flow_dissect_get_header(skb, sizeof(*mpls), &_mpls);
  if (!mpls)
    return export_flow_keys(keys, BPF_DROP);
  return export_flow_keys(keys, BPF_OK);
}


x86 assembly (clang, -O0):
<bpf_func_MPLS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
lea    -0x28(%rbp),%rdx
call   1040 <bpf_flow_dissect_get_header@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1172 <bpf_func_MPLS+0x52>
mov    -0x18(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1030 <export_flow_keys@plt>
mov    %eax,-0x4(%rbp)
jmp    1187 <bpf_func_MPLS+0x67>
mov    -0x18(%rbp),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1030 <export_flow_keys@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_func_MPLS>:
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%rbx
lea    0x8(%rsp),%rdx
mov    $0x4,%esi
call   1040 <bpf_flow_dissect_get_header@plt>
test   %rax,%rax
jne    1145 <bpf_func_MPLS+0x25>
mov    0x2e9d(%rip),%rax
jmp    114c <bpf_func_MPLS+0x2c>
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <export_flow_keys@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.__sk_buff = type { %struct.bpf_flow_keys* }
%struct.bpf_flow_keys = type { i32 }
%struct.mpls_label = type { i32 }
@BPF_DROP = global i32 0
@BPF_OK = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @bpf_func_MPLS to i8*)], section "llvm.metadata"
define i32 @bpf_func_MPLS(%struct.__sk_buff* %0) section "MPLS" {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
%4 = alloca %struct.bpf_flow_keys*
%5 = alloca %struct.mpls_label*
%6 = alloca %struct.mpls_label
store %struct.__sk_buff* %0, %struct.__sk_buff** %3
%7 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%8 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %7, i32 0, i32 0
%9 = load %struct.bpf_flow_keys*, %struct.bpf_flow_keys** %8
store %struct.bpf_flow_keys* %9, %struct.bpf_flow_keys** %4
%10 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%11 = call %struct.mpls_label* @bpf_flow_dissect_get_header(%struct.__sk_buff* %10, i32 4, %struct.mpls_label* %6)
store %struct.mpls_label* %11, %struct.mpls_label** %5
%12 = load %struct.mpls_label*, %struct.mpls_label** %5
%13 = icmp ne %struct.mpls_label* %12, null
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load %struct.bpf_flow_keys*, %struct.bpf_flow_keys** %4
%16 = load i32, i32* @BPF_DROP
%17 = call i32 @export_flow_keys(%struct.bpf_flow_keys* %15, i32 %16)
store i32 %17, i32* %2
br label %22
18: ; preds = %1
%19 = load %struct.bpf_flow_keys*, %struct.bpf_flow_keys** %4
%20 = load i32, i32* @BPF_OK
%21 = call i32 @export_flow_keys(%struct.bpf_flow_keys* %19, i32 %20)
store i32 %21, i32* %2
br label %22
22: ; preds = %18, %14
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.__sk_buff = type { %struct.bpf_flow_keys* }
%struct.bpf_flow_keys = type { i32 }
%struct.mpls_label = type { i32 }
@BPF_DROP = global i32 0
@BPF_OK = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @bpf_func_MPLS to i8*)], section "llvm.metadata"
define i32 @bpf_func_MPLS(%struct.__sk_buff* %0) section "MPLS" {
%2 = alloca %struct.mpls_label
%3 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 0
%4 = load %struct.bpf_flow_keys*, %struct.bpf_flow_keys** %3
%5 = bitcast %struct.mpls_label* %2 to i8*
%6 = call %struct.mpls_label* @bpf_flow_dissect_get_header(%struct.__sk_buff* %0, i32 4, %struct.mpls_label* %2)
%7 = icmp eq %struct.mpls_label* %6, null
%8 = load i32, i32* @BPF_DROP
%9 = load i32, i32* @BPF_OK
%10 = select i1 %7, i32 %8, i32 %9
%11 = call i32 @export_flow_keys(%struct.bpf_flow_keys* %4, i32 %10)
ret i32 %11
}