#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;
  void *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*/ bzero(union bpf_attr *, int);
void *ptr_to_u64(char const *);
int sys_bpf_prog_load(union bpf_attr *, int);
int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
                       size_t insns_cnt, __u32 prog_flags, 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 = prog_flags;
  return sys_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    %rcx,-0x20(%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   1030 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    0x10(%rbp),%rdi
call   1030 <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)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
mov    $0x8,%esi
call   1040 <sys_bpf_prog_load@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_verify_program>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbx
mov    %rcx,%r14
mov    %rsi,%rdi
mov    0x30(%rsp),%r15
call   1030 <ptr_to_u64@plt>
mov    %rbx,%rdi
call   1030 <ptr_to_u64@plt>
mov    %r15,%rdi
call   1030 <ptr_to_u64@plt>
movb   $0x0,(%r15)
mov    %r14,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
call   1040 <sys_bpf_prog_load@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.bpf_insn = type opaque
%union.bpf_attr = type { i64 }
define i32 @bpf_verify_program(i32 %0, %struct.bpf_insn* %1, i64 %2, i8* %3, i8* %4, i8* %5, i8* %6, i64 %7, i32 %8) {
%10 = alloca i32
%11 = alloca %struct.bpf_insn*
%12 = alloca i64
%13 = alloca i8*
%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 i8* %3, i8** %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 i8*, i8** %13
%45 = bitcast %union.bpf_attr* %19 to i8**
store i8* %44, i8** %45
%46 = call i32 @sys_bpf_prog_load(%union.bpf_attr* %19, i32 8)
ret i32 %46
}

LLVM IR (-O2):
%struct.bpf_insn = type opaque
%union.bpf_attr = type { i64 }
define i32 @bpf_verify_program(i32 %0, %struct.bpf_insn* %1, i64 %2, i8* %3, i8* %4, i8* nocapture readnone %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 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* %3, i8** %12
%17 = call i32 @sys_bpf_prog_load(%union.bpf_attr* %10, i32 8)
ret i32 %17
}