#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__ data_end;
  scalar_t__ data;
};

/* Variables and functions */
int /*<<< orphan*/ bpf_trace_printk(char *, int, int);
__attribute__((section(".classifier"), used)) int
process_packet(struct __sk_buff *skb) {
  char needle[] = {'H', 'E', 'L', 'L', 'O'};
  void *data = (void *)(long)skb->data;
  void *data_end = (void *)(long)skb->data_end;
  int data_len = data_end - data + 1;
  bpf_trace_printk("%d", sizeof("%d"), data_len);
  int i = 0;
  int j = 0;
  for (i = 54; i < data_len; i++) {
    if (((char *)data)[i] == needle[j]) {
      if (j == 5 - 1) {
        return i - (5 - 1) - 54;
      } else {
        j++;
      }
    } else {
      j = 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<process_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xede(%rip),%eax
mov    %eax,-0x15(%rbp)
mov    0xed9(%rip),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edx
lea    0xea4(%rip),%rdi
mov    $0x3,%esi
call   1030 <bpf_trace_printk@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x36,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    11ec <process_packet+0xdc>
mov    -0x20(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movslq -0x34(%rbp),%rcx
movsbl -0x15(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    11d2 <process_packet+0xc2>
cmpl   $0x4,-0x34(%rbp)
jne    11c4 <process_packet+0xb4>
mov    -0x30(%rbp),%eax
sub    $0x4,%eax
sub    $0x36,%eax
mov    %eax,-0x4(%rbp)
jmp    11f3 <process_packet+0xe3>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d9 <process_packet+0xc9>
movl   $0x0,-0x34(%rbp)
jmp    11de <process_packet+0xce>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1180 <process_packet+0x70>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_packet>:
push   %r14
push   %rbx
push   %rax
mov    0x8(%rdi),%r14
mov    (%rdi),%ebx
sub    %r14d,%ebx
add    $0x1,%ebx
lea    0xede(%rip),%rdi
mov    $0x3,%esi
mov    %ebx,%edx
call   1030 <bpf_trace_printk@plt>
mov    $0xffffffff,%eax
cmp    $0x37,%ebx
jl     1190 <process_packet+0x80>
mov    %ebx,%r9d
add    $0xffffffffffffffca,%r9
xor    %ecx,%ecx
lea    0xeb3(%rip),%r8
xor    %edi,%edi
jmp    116b <process_packet+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rcx
mov    %ebx,%edi
cmp    %rcx,%r9
je     1190 <process_packet+0x80>
movzbl 0x36(%r14,%rcx,1),%edx
movslq %edi,%rsi
mov    $0x0,%ebx
cmp    (%rsi,%r8,1),%dl
jne    1160 <process_packet+0x50>
cmp    $0x4,%edi
je     118b <process_packet+0x7b>
add    $0x1,%edi
mov    %edi,%ebx
jmp    1160 <process_packet+0x50>
add    $0xfffffffc,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.__sk_buff = type { i64, i64 }
@__const.process_packet.needle = [5 x i8] c"HELLO"
@.str = [3 x i8] c"%d\00"
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.__sk_buff*)* @process_packet to i8*)], section "llvm.metadata"
define i32 @process_packet(%struct.__sk_buff* nocapture %0) section ".classifier" {
%2 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 1
%3 = load i64, i64* %2
%4 = inttoptr i64 %3 to i8*
%5 = getelementptr inbounds %struct.__sk_buff, %struct.__sk_buff* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = sub i64 %6, %3
%8 = trunc i64 %7 to i32
%9 = add i32 %8, 1
%10 = tail call i32 @bpf_trace_printk(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3, i32 %9)
%11 = icmp sgt i32 %9, 54
br i1 %11, label %12, label %34
12: ; preds = %1
%13 = zext i32 %9 to i64
br label %14
14: ; preds = %12, %30
%15 = phi i64 [ 54, %12 ], [ %32, %30 ]
%16 = phi i32 [ 0, %12 ], [ %31, %30 ]
%17 = getelementptr inbounds i8, i8* %4, i64 %15
%18 = load i8, i8* %17
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds [5 x i8], [5 x i8]* @__const.process_packet.needle, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %18, %21
br i1 %22, label %23, label %30
23: ; preds = %14
%24 = icmp eq i32 %16, 4
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = trunc i64 %15 to i32
%27 = add nsw i32 %26, -58
br label %34
28: ; preds = %23
%29 = add nsw i32 %16, 1
br label %30
30: ; preds = %14, %28
%31 = phi i32 [ %29, %28 ], [ 0, %14 ]
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, %13
br i1 %33, label %34, label %14
34: ; preds = %30, %1, %25
%35 = phi i32 [ %27, %25 ], [ -1, %1 ], [ -1, %30 ]
ret i32 %35
}