#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 __sk_buff {
  scalar_t__ protocol;
};

/* Variables and functions */
int /*<<< orphan*/ ETH_P_IP;
int /*<<< orphan*/ ETH_P_TEB;
int /*<<< orphan*/ IPPROTO_UDP;
int TC_ACT_OK;
scalar_t__ ___constant_swab16(int /*<<< orphan*/);
int encap_ipv4(struct __sk_buff *, int /*<<< orphan*/, int /*<<< orphan*/);
__attribute__((section("encap_udp_eth"), used)) int
__encap_udp_eth(struct __sk_buff *skb) {
  if (skb->protocol == ___constant_swab16(ETH_P_IP))
    return encap_ipv4(skb, IPPROTO_UDP, ETH_P_TEB);
  else
    return TC_ACT_OK;
}


x86 assembly (clang, -O0):
<__encap_udp_eth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
call   1040 <___constant_swab16@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cmp    %rcx,%rax
jne    1178 <__encap_udp_eth+0x58>
mov    -0x10(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
call   1030 <encap_ipv4@plt>
mov    %eax,-0x4(%rbp)
jmp    1184 <__encap_udp_eth+0x64>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__encap_udp_eth>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    0x2ea7(%rip),%rax
mov    (%rax),%edi
call   1040 <___constant_swab16@plt>
cmp    %rax,%rbx
jne    115e <__encap_udp_eth+0x3e>
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    0x2e83(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <encap_ipv4@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i64 }
@ETH_P_IP = global i32 0
@IPPROTO_UDP = global i32 0
@ETH_P_TEB = global i32 0
@TC_ACT_OK = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @__encap_udp_eth to i8*)], section "llvm.metadata"
define i32 @__encap_udp_eth(%struct.__sk_buff* %0) section "encap_udp_eth" {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
store %struct.__sk_buff* %0, %struct.__sk_buff** %3
%4 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%5 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %4, i32 0, i32 0
%6 = load i64, i64* %5
%7 = load i32, i32* @ETH_P_IP
%8 = call i64 @___constant_swab16(i32 %7)
%9 = icmp eq i64 %6, %8
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%12 = load i32, i32* @IPPROTO_UDP
%13 = load i32, i32* @ETH_P_TEB
%14 = call i32 @encap_ipv4(%struct.__sk_buff* %11, i32 %12, i32 %13)
store i32 %14, i32* %2
br label %17
15: ; preds = %1
%16 = load i32, i32* @TC_ACT_OK
store i32 %16, i32* %2
br label %17
17: ; preds = %15, %10
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.__sk_buff = type { i64 }
@ETH_P_IP = global i32 0
@IPPROTO_UDP = global i32 0
@ETH_P_TEB = global i32 0
@TC_ACT_OK = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @__encap_udp_eth to i8*)], section "llvm.metadata"
define i32 @__encap_udp_eth(%struct.__sk_buff* %0) section "encap_udp_eth" {
%2 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = load i32, i32* @ETH_P_IP
%5 = tail call i64 @___constant_swab16(i32 %4)
%6 = icmp eq i64 %3, %5
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @IPPROTO_UDP
%9 = load i32, i32* @ETH_P_TEB
%10 = tail call i32 @encap_ipv4(%struct.__sk_buff* %0, i32 %8, i32 %9)
br label %13
11: ; preds = %1
%12 = load i32, i32* @TC_ACT_OK
br label %13
13: ; preds = %11, %7
%14 = phi i32 [ %10, %7 ], [ %12, %11 ]
ret i32 %14
}