#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) {
  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 = 2;
  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    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)
movl   $0x2,-0x38(%rbp)
mov    0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11d2 <bpf_verify_program+0xa2>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    11dc <bpf_verify_program+0xac>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    11dc <bpf_verify_program+0xac>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dff(%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) {
%9 = alloca i32
%10 = alloca %struct.bpf_insn*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca %union.bpf_attr
store i32 %0, i32* %9
store %struct.bpf_insn* %1, %struct.bpf_insn** %10
store i64 %2, i64* %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
store i64 %7, i64* %16
%18 = call i32 @bzero(%union.bpf_attr* %17, i32 8)
%19 = load i32, i32* %9
%20 = bitcast %union.bpf_attr* %17 to i32*
store i32 %19, i32* %20
%21 = load i64, i64* %11
%22 = inttoptr i64 %21 to i8*
%23 = bitcast %union.bpf_attr* %17 to i8**
store i8* %22, i8** %23
%24 = load %struct.bpf_insn*, %struct.bpf_insn** %10
%25 = bitcast %struct.bpf_insn* %24 to i8*
%26 = call i8* @ptr_to_u64(i8* %25)
%27 = bitcast %union.bpf_attr* %17 to i8**
store i8* %26, i8** %27
%28 = load i8*, i8** %13
%29 = call i8* @ptr_to_u64(i8* %28)
%30 = bitcast %union.bpf_attr* %17 to i8**
store i8* %29, i8** %30
%31 = load i8*, i8** %15
%32 = call i8* @ptr_to_u64(i8* %31)
%33 = bitcast %union.bpf_attr* %17 to i8**
store i8* %32, i8** %33
%34 = load i64, i64* %16
%35 = bitcast %union.bpf_attr* %17 to i64*
store i64 %34, i64* %35
%36 = bitcast %union.bpf_attr* %17 to i32*
store i32 2, i32* %36
%37 = load i8*, i8** %15
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 0, i8* %38
%39 = load i8*, i8** %14
%40 = bitcast %union.bpf_attr* %17 to i8**
store i8* %39, i8** %40
%41 = load i32, i32* %12
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %8
%44 = load i32, i32* @BPF_F_STRICT_ALIGNMENT
br label %46
45: ; preds = %8
br label %46
46: ; preds = %45, %43
%47 = phi i32 [ %44, %43 ], [ 0, %45 ]
%48 = bitcast %union.bpf_attr* %17 to i32*
store i32 %47, i32* %48
%49 = load i32, i32* @BPF_PROG_LOAD
%50 = call i32 @sys_bpf(i32 %49, %union.bpf_attr* %17, i32 8)
ret i32 %50
}

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) {
%9 = alloca %union.bpf_attr
%10 = bitcast %union.bpf_attr* %9 to i8*
%11 = bitcast %union.bpf_attr* %9 to i32*
%12 = bitcast %union.bpf_attr* %9 to i8**
%13 = bitcast %struct.bpf_insn* %1 to i8*
%14 = tail call i8* @ptr_to_u64(i8* %13)
%15 = tail call i8* @ptr_to_u64(i8* %4)
%16 = tail call i8* @ptr_to_u64(i8* %6)
store i8 0, i8* %6
store i8* %5, i8** %12
%17 = icmp eq i32 %3, 0
%18 = load i32, i32* @BPF_F_STRICT_ALIGNMENT
%19 = select i1 %17, i32 0, i32 %18
store i32 %19, i32* %11
%20 = load i32, i32* @BPF_PROG_LOAD
%21 = call i32 @sys_bpf(i32 %20, %union.bpf_attr* %9, i32 8)
ret i32 %21
}