#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 {
  int len;
  scalar_t__ data;
  scalar_t__ data_end;
  scalar_t__ remote_port;
  scalar_t__ local_port;
};
typedef int __u8;
typedef scalar_t__ __u32;

/* Variables and functions */
int SK_DROP;
int bpf_skb_pull_data(struct __sk_buff *, int);
__attribute__((section("sk_skb1"), used)) int bpf_prog1(struct __sk_buff *skb) {
  void *data_end = (void *)(long)skb->data_end;
  void *data = (void *)(long)skb->data;
  __u32 lport = skb->local_port;
  __u32 rport = skb->remote_port;
  __u8 *d = data;
  __u32 len = (__u32)data_end - (__u32)data;
  int err;
  if (data + 10 > data_end) {
    err = bpf_skb_pull_data(skb, 10);
    if (err)
      return SK_DROP;
    data_end = (void *)(long)skb->data_end;
    data = (void *)(long)skb->data;
    if (data + 10 > data_end)
      return SK_DROP;
  }
  d = data;
  d[7] = 1;
  return skb->len;
}


x86 assembly (clang, -O0):
<bpf_prog1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
add    $0xa,%rax
cmp    -0x18(%rbp),%rax
jbe    11e1 <bpf_prog1+0xd1>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1030 <bpf_skb_pull_data@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     11a1 <bpf_prog1+0x91>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <bpf_prog1+0xed>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xa,%rax
cmp    -0x18(%rbp),%rax
jbe    11dc <bpf_prog1+0xcc>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11fd <bpf_prog1+0xed>
jmp    11e1 <bpf_prog1+0xd1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x1,0x1c(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog1>:
push   %rbx
mov    %rdi,%rbx
mov    0x8(%rdi),%rax
lea    0xa(%rax),%rcx
cmp    0x10(%rdi),%rcx
jbe    1148 <bpf_prog1+0x38>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <bpf_skb_pull_data@plt>
mov    0x2eb2(%rip),%rcx
test   %eax,%eax
jne    1152 <bpf_prog1+0x42>
mov    0x8(%rbx),%rax
lea    0xa(%rax),%rdx
cmp    0x10(%rbx),%rdx
ja     1152 <bpf_prog1+0x42>
movl   $0x1,0x1c(%rax)
mov    %rbx,%rcx
mov    (%rcx),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.__sk_buff = type { i32, i64, i64, i64, i64 }
@SK_DROP = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @bpf_prog1 to i8*)], section "llvm.metadata"
define i32 @bpf_prog1(%struct.__sk_buff* %0) section "sk_skb1" {
%2 = alloca i32
%3 = alloca %struct.__sk_buff*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i32
store %struct.__sk_buff* %0, %struct.__sk_buff** %3
%11 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%12 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %11, i32 0, i32 2
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%16 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%20 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %19, i32 0, i32 4
%21 = load i64, i64* %20
store i64 %21, i64* %6
%22 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%23 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %22, i32 0, i32 3
%24 = load i64, i64* %23
store i64 %24, i64* %7
%25 = load i8*, i8** %5
%26 = bitcast i8* %25 to i32*
store i32* %26, i32** %8
%27 = load i8*, i8** %4
%28 = ptrtoint i8* %27 to i64
%29 = load i8*, i8** %5
%30 = ptrtoint i8* %29 to i64
%31 = sub nsw i64 %28, %30
store i64 %31, i64* %9
%32 = load i8*, i8** %5
%33 = getelementptr i8, i8* %32, i64 10
%34 = load i8*, i8** %4
%35 = icmp ugt i8* %33, %34
br i1 %35, label %36, label %59
36: ; preds = %1
%37 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%38 = call i32 @bpf_skb_pull_data(%struct.__sk_buff* %37, i32 10)
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i32, i32* @SK_DROP
store i32 %42, i32* %2
br label %67
43: ; preds = %36
%44 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%45 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %44, i32 0, i32 2
%46 = load i64, i64* %45
%47 = inttoptr i64 %46 to i8*
store i8* %47, i8** %4
%48 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%49 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %48, i32 0, i32 1
%50 = load i64, i64* %49
%51 = inttoptr i64 %50 to i8*
store i8* %51, i8** %5
%52 = load i8*, i8** %5
%53 = getelementptr i8, i8* %52, i64 10
%54 = load i8*, i8** %4
%55 = icmp ugt i8* %53, %54
br i1 %55, label %56, label %58
56: ; preds = %43
%57 = load i32, i32* @SK_DROP
store i32 %57, i32* %2
br label %67
58: ; preds = %43
br label %59
59: ; preds = %58, %1
%60 = load i8*, i8** %5
%61 = bitcast i8* %60 to i32*
store i32* %61, i32** %8
%62 = load i32*, i32** %8
%63 = getelementptr inbounds i32, i32* %62, i64 7
store i32 1, i32* %63
%64 = load %struct.__sk_buff*, %struct.__sk_buff** %3
%65 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %64, i32 0, i32 0
%66 = load i32, i32* %65
store i32 %66, i32* %2
br label %67
67: ; preds = %59, %56, %41
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
%struct.__sk_buff = type { i32, i64, i64, i64, i64 }
@SK_DROP = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @bpf_prog1 to i8*)], section "llvm.metadata"
define i32 @bpf_prog1(%struct.__sk_buff* %0) section "sk_skb1" {
%2 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 2
%3 = load i64, i64* %2
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = inttoptr i64 %6 to i8*
%8 = getelementptr i8, i8* %7, i64 10
%9 = icmp ugt i8* %8, %4
br i1 %9, label %10, label %20
10: ; preds = %1
%11 = tail call i32 @bpf_skb_pull_data(%struct.__sk_buff* %0, i32 10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i64, i64* %2
%15 = inttoptr i64 %14 to i8*
%16 = load i64, i64* %5
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr i8, i8* %17, i64 10
%19 = icmp ugt i8* %18, %15
br i1 %19, label %25, label %20
20: ; preds = %13, %1
%21 = phi i8* [ %17, %13 ], [ %7, %1 ]
%22 = getelementptr inbounds i8, i8* %21, i64 28
%23 = bitcast i8* %22 to i32*
store i32 1, i32* %23
%24 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 0
br label %25
25: ; preds = %13, %10, %20
%26 = phi i32* [ %24, %20 ], [ @SK_DROP, %10 ], [ @SK_DROP, %13 ]
%27 = load i32, i32* %26
ret i32 %27
}