#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 */
union bpf_attr {
  int prog_type;
  size_t log_size;
  int log_level;
  int /*<<< orphan*/ prog_flags;
  void *kern_version;
  void *log_buf;
  void *license;
  void *insns;
  void *insn_cnt;
};
typedef char bpf_insn;
typedef enum bpf_prog_type { ____Placeholder_bpf_prog_type } bpf_prog_type;
typedef int /*<<< orphan*/ attr;
typedef void *__u32;

/* Variables and functions */
int /*<<< orphan*/ BPF_F_STRICT_ALIGNMENT;
int /*<<< orphan*/ BPF_PROG_LOAD;
int /*<<< orphan*/ bzero(union bpf_attr *, int);
void *ptr_to_u64(char const *);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
                       size_t insns_cnt, int strict_alignment,
                       const char *license, __u32 kern_version, char *log_buf,
                       size_t log_buf_sz, int log_level) {
  union bpf_attr attr;
  bzero(&attr, sizeof(attr));
  attr.prog_type = type;
  attr.insn_cnt = (__u32)insns_cnt;
  attr.insns = ptr_to_u64(insns);
  attr.license = ptr_to_u64(license);
  attr.log_buf = ptr_to_u64(log_buf);
  attr.log_size = log_buf_sz;
  attr.log_level = log_level;
  log_buf[0] = 0;
  attr.kern_version = kern_version;
  attr.prog_flags = strict_alignment ? BPF_F_STRICT_ALIGNMENT : 0;
  return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
}


x86 assembly (clang, -O0):
<bpf_verify_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   1050 <bzero@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    0x10(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d4 <bpf_verify_program+0xa4>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    11de <bpf_verify_program+0xae>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11de <bpf_verify_program+0xae>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
mov    $0x8,%edx
call   1030 <sys_bpf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_verify_program>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %ecx,%ebx
mov    %rsi,%rdi
mov    0x30(%rsp),%r12
call   1040 <ptr_to_u64@plt>
mov    %r15,%rdi
call   1040 <ptr_to_u64@plt>
mov    %r12,%rdi
call   1040 <ptr_to_u64@plt>
movb   $0x0,(%r12)
mov    %r14,(%rsp)
test   %ebx,%ebx
je     1163 <bpf_verify_program+0x43>
mov    0x2e7f(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,(%rsp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x8,%edx
call   1030 <sys_bpf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bpf_insn = type opaque
%union.bpf_attr = type { i64 }
@BPF_F_STRICT_ALIGNMENT = global i32 0
@BPF_PROG_LOAD = global i32 0
define i32 @bpf_verify_program(i32 %0, %struct.bpf_insn* %1, i64 %2, i32 %3, i8* %4, i8* %5, i8* %6, i64 %7, i32 %8) {
%10 = alloca i32
%11 = alloca %struct.bpf_insn*
%12 = alloca i64
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
%19 = alloca %union.bpf_attr
store i32 %0, i32* %10
store %struct.bpf_insn* %1, %struct.bpf_insn** %11
store i64 %2, i64* %12
store i32 %3, i32* %13
store i8* %4, i8** %14
store i8* %5, i8** %15
store i8* %6, i8** %16
store i64 %7, i64* %17
store i32 %8, i32* %18
%20 = call i32 @bzero(%union.bpf_attr* %19, i32 8)
%21 = load i32, i32* %10
%22 = bitcast %union.bpf_attr* %19 to i32*
store i32 %21, i32* %22
%23 = load i64, i64* %12
%24 = inttoptr i64 %23 to i8*
%25 = bitcast %union.bpf_attr* %19 to i8**
store i8* %24, i8** %25
%26 = load %struct.bpf_insn*, %struct.bpf_insn** %11
%27 = bitcast %struct.bpf_insn* %26 to i8*
%28 = call i8* @ptr_to_u64(i8* %27)
%29 = bitcast %union.bpf_attr* %19 to i8**
store i8* %28, i8** %29
%30 = load i8*, i8** %14
%31 = call i8* @ptr_to_u64(i8* %30)
%32 = bitcast %union.bpf_attr* %19 to i8**
store i8* %31, i8** %32
%33 = load i8*, i8** %16
%34 = call i8* @ptr_to_u64(i8* %33)
%35 = bitcast %union.bpf_attr* %19 to i8**
store i8* %34, i8** %35
%36 = load i64, i64* %17
%37 = bitcast %union.bpf_attr* %19 to i64*
store i64 %36, i64* %37
%38 = load i32, i32* %18
%39 = bitcast %union.bpf_attr* %19 to i32*
store i32 %38, i32* %39
%40 = load i8*, i8** %16
%41 = getelementptr inbounds i8, i8* %40, i64 0
store i8 0, i8* %41
%42 = load i8*, i8** %15
%43 = bitcast %union.bpf_attr* %19 to i8**
store i8* %42, i8** %43
%44 = load i32, i32* %13
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %9
%47 = load i32, i32* @BPF_F_STRICT_ALIGNMENT
br label %49
48: ; preds = %9
br label %49
49: ; preds = %48, %46
%50 = phi i32 [ %47, %46 ], [ 0, %48 ]
%51 = bitcast %union.bpf_attr* %19 to i32*
store i32 %50, i32* %51
%52 = load i32, i32* @BPF_PROG_LOAD
%53 = call i32 @sys_bpf(i32 %52, %union.bpf_attr* %19, i32 8)
ret i32 %53
}

LLVM IR (-O2):
%struct.bpf_insn = type opaque
%union.bpf_attr = type { i64 }
@BPF_F_STRICT_ALIGNMENT = global i32 0
@BPF_PROG_LOAD = global i32 0
define i32 @bpf_verify_program(i32 %0, %struct.bpf_insn* %1, i64 %2, i32 %3, i8* %4, i8* %5, i8* %6, i64 %7, i32 %8) {
%10 = alloca %union.bpf_attr
%11 = bitcast %union.bpf_attr* %10 to i8*
%12 = bitcast %union.bpf_attr* %10 to i32*
%13 = bitcast %union.bpf_attr* %10 to i8**
%14 = bitcast %struct.bpf_insn* %1 to i8*
%15 = tail call i8* @ptr_to_u64(i8* %14)
%16 = tail call i8* @ptr_to_u64(i8* %4)
%17 = tail call i8* @ptr_to_u64(i8* %6)
store i8 0, i8* %6
store i8* %5, i8** %13
%18 = icmp eq i32 %3, 0
%19 = load i32, i32* @BPF_F_STRICT_ALIGNMENT
%20 = select i1 %18, i32 0, i32 %19
store i32 %20, i32* %12
%21 = load i32, i32* @BPF_PROG_LOAD
%22 = call i32 @sys_bpf(i32 %21, %union.bpf_attr* %10, i32 8)
ret i32 %22
}