#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;
typedef int /*<<< orphan*/ ____fmt;

/* Variables and functions */
int SK_DROP;
int SK_PASS;
int /*<<< orphan*/ bpf_trace_printk(char *, int, 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;
  ({
    char ____fmt[] = "data length %i\n";
    bpf_trace_printk(____fmt, sizeof(____fmt),
                     (__u64)msg->data_end - (__u64)msg->data);
  });
  d = (char *)data;
  ({
    char ____fmt[] = "hello sendmsg hook %i %i\n";
    bpf_trace_printk(____fmt, sizeof(____fmt), d[0], d[1]);
  });
  return SK_PASS;
}


x86 assembly (clang, -O0):
<bpf_prog1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    11f5 <bpf_prog1+0xe5>
mov    0xea3(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea0(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    $0x10,%esi
movsbl %al,%edx
mov    $0x0,%al
call   1030 <bpf_trace_printk@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0xe70(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe6d(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe67(%rip),%ax
mov    %ax,-0x48(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%al
mov    -0x28(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
mov    $0x1a,%esi
movsbl %al,%edx
mov    $0x0,%al
call   1030 <bpf_trace_printk@plt>
mov    %eax,-0x64(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog1>:
push   %rbx
sub    $0x20,%rsp
mov    (%rdi),%rbx
mov    0x8(%rdi),%rax
lea    0x8(%rbx),%rcx
cmp    %rax,%rcx
jbe    112e <bpf_prog1+0x1e>
mov    0x2eb4(%rip),%rax
jmp    1181 <bpf_prog1+0x71>
movaps 0xecb(%rip),%xmm0
movaps %xmm0,(%rsp)
sub    %ebx,%eax
movsbl %al,%edx
mov    %rsp,%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <bpf_trace_printk@plt>
movups 0xec6(%rip),%xmm0
movups %xmm0,0xa(%rsp)
movaps 0xeb0(%rip),%xmm0
movaps %xmm0,(%rsp)
movsbl (%rbx),%edx
movsbl 0x1(%rbx),%ecx
mov    %rsp,%rdi
mov    $0x1a,%esi
xor    %eax,%eax
call   1030 <bpf_trace_printk@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sk_msg_md = type { i64, i64 }
@SK_DROP = global i32 0
@__const.bpf_prog1.____fmt = [16 x i8] c"data length %i\0A\00"
@__const.bpf_prog1.____fmt.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*
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca [26 x i8]
%10 = alloca i32
store %struct.sk_msg_md* %0, %struct.sk_msg_md** %3
%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 1
%13 = load i64, i64* %12
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %4
%15 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%16 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = getelementptr i8, i8* %19, i64 8
%21 = load i8*, i8** %4
%22 = icmp ugt i8* %20, %21
br i1 %22, label %23, label %25
23: ; preds = %1
%24 = load i32, i32* @SK_DROP
store i32 %24, i32* %2
br label %51
25: ; preds = %1
%26 = bitcast [16 x i8]* %7 to i8*
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%28 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%29 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = load %struct.sk_msg_md*, %struct.sk_msg_md** %3
%32 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = sub nsw i64 %30, %33
%35 = trunc i64 %34 to i8
%36 = call i32 (i8*, i32, i8, ...) @bpf_trace_printk(i8* %27, i32 16, i8 signext %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = load i8*, i8** %5
store i8* %38, i8** %6
%39 = bitcast [26 x i8]* %9 to i8*
%40 = getelementptr inbounds [26 x i8], [26 x i8]* %9, i64 0, i64 0
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = load i8*, i8** %6
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, i32, i8, ...) @bpf_trace_printk(i8* %40, i32 26, i8 signext %43, i32 %47)
store i32 %48, i32* %10
%49 = load i32, i32* %10
%50 = load i32, i32* @SK_PASS
store i32 %50, i32* %2
br label %51
51: ; preds = %25, %23
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
%struct.sk_msg_md = type { i64, i64 }
@SK_DROP = global i32 0
@__const.bpf_prog1.____fmt = [16 x i8] c"data length %i\0A\00"
@__const.bpf_prog1.____fmt.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 = alloca [16 x i8]
%3 = alloca [26 x i8]
%4 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %0, i64 0, i32 1
%5 = load i64, i64* %4
%6 = inttoptr i64 %5 to i8*
%7 = getelementptr inbounds %struct.sk_msg_md, %struct.sk_msg_md* %0, i64 0, i32 0
%8 = load i64, i64* %7
%9 = inttoptr i64 %8 to i8*
%10 = getelementptr i8, i8* %9, i64 8
%11 = icmp ugt i8* %10, %6
br i1 %11, label %23, label %12
12: ; preds = %1
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%14 = sub nsw i64 %5, %8
%15 = trunc i64 %14 to i8
%16 = call i32 (i8*, i32, i8, ...) @bpf_trace_printk(i8* %13, i32 16, i8 signext %15)
%17 = getelementptr inbounds [26 x i8], [26 x i8]* %3, i64 0, i64 0
%18 = load i8, i8* %9
%19 = getelementptr inbounds i8, i8* %9, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, i32, i8, ...) @bpf_trace_printk(i8* %17, i32 26, i8 signext %18, i32 %21)
br label %23
23: ; preds = %1, %12
%24 = phi i32* [ @SK_PASS, %12 ], [ @SK_DROP, %1 ]
%25 = load i32, i32* %24
ret i32 %25
}