#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_msg_md {
  scalar_t__ data;
  scalar_t__ data_end;
};
typedef scalar_t__ __u64;

/* Variables and functions */
int SK_DROP;
int SK_PASS;
int /*<<< orphan*/ bpf_printk(char *, char, ...);
__attribute__((section("sk_msg1"), used)) int bpf_prog1(struct sk_msg_md *msg) {
  void *data_end = (void *)(long)msg->data_end;
  void *data = (void *)(long)msg->data;
  char *d;
  if (data + 8 > data_end)
    return SK_DROP;
  bpf_printk("data length %i\n", (__u64)msg->data_end - (__u64)msg->data);
  d = (char *)data;
  bpf_printk("hello sendmsg hook %i %i\n", d[0], d[1]);
  return SK_PASS;
}


x86 assembly (clang, -O0):
<bpf_prog1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
cmp    -0x18(%rbp),%rax
jbe    1156 <bpf_prog1+0x46>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a9 <bpf_prog1+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
lea    0xe94(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <bpf_printk@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    -0x28(%rbp),%rcx
movsbl 0x1(%rcx),%edx
lea    0xe7d(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <bpf_printk@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog1>:
push   %rbx
mov    (%rdi),%rbx
mov    0x8(%rdi),%rax
lea    0x8(%rbx),%rcx
cmp    %rax,%rcx
jbe    112a <bpf_prog1+0x1a>
mov    0x2eb8(%rip),%rax
jmp    1159 <bpf_prog1+0x49>
sub    %ebx,%eax
movsbl %al,%esi
lea    0xeca(%rip),%rdi
xor    %eax,%eax
call   1030 <bpf_printk@plt>
movsbl (%rbx),%esi
movsbl 0x1(%rbx),%edx
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1030 <bpf_printk@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.sk_msg_md = type { i64, i64 }
@SK_DROP = global i32 0
@.str = [16 x i8] c"data length %i\0A\00"
@.str.1 = [26 x i8] c"hello sendmsg hook %i %i\0A\00"
@SK_PASS = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.sk_msg_md*)* @bpf_prog1 to i8*)], section "llvm.metadata"
define i32 @bpf_prog1(%struct.sk_msg_md* %0) section "sk_msg1" {
%2 = alloca i32
%3 = alloca %struct.sk_msg_md*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store %struct.sk_msg_md* %0, %struct.sk_msg_md** %3
%7 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%8 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %7, i32 0, i32 1
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%12 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %11, i32 0, i32 0
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = getelementptr i8, i8* %15, i64 8
%17 = load i8*, i8** %4
%18 = icmp ugt i8* %16, %17
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = load i32, i32* @SK_DROP
store i32 %20, i32* %2
br label %41
21: ; preds = %1
%22 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%23 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%26 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = sub nsw i64 %24, %27
%29 = trunc i64 %28 to i8
%30 = call i32 (i8*, i8, ...) @bpf_printk(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %29)
%31 = load i8*, i8** %5
store i8* %31, i8** %6
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, i8, ...) @bpf_printk(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 signext %34, i32 %38)
%40 = load i32, i32* @SK_PASS
store i32 %40, i32* %2
br label %41
41: ; preds = %21, %19
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
%struct.sk_msg_md = type { i64, i64 }
@SK_DROP = global i32 0
@.str = [16 x i8] c"data length %i\0A\00"
@.str.1 = [26 x i8] c"hello sendmsg hook %i %i\0A\00"
@SK_PASS = global i32 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.sk_msg_md*)* @bpf_prog1 to i8*)], section "llvm.metadata"
define i32 @bpf_prog1(%struct.sk_msg_md* nocapture %0) section "sk_msg1" {
%2 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %0, i64 0, i32 1
%3 = load i64, i64* %2
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = inttoptr i64 %6 to i8*
%8 = getelementptr i8, i8* %7, i64 8
%9 = icmp ugt i8* %8, %4
br i1 %9, label %19, label %10
10: ; preds = %1
%11 = sub nsw i64 %3, %6
%12 = trunc i64 %11 to i8
%13 = tail call i32 (i8*, i8, ...) @bpf_printk(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = load i8, i8* %7
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = tail call i32 (i8*, i8, ...) @bpf_printk(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8 signext %14, i32 %17)
br label %19
19: ; preds = %1, %10
%20 = phi i32* [ @SK_PASS, %10 ], [ @SK_DROP, %1 ]
%21 = load i32, i32* %20
ret i32 %21
}