#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;
  int insn_cnt;
  unsigned int log_size;
  int log_level;
  unsigned int kern_version;
  void *log_buf;
  void *license;
  void *insns;
};
struct rlimit {
  int /*<<< orphan*/ rlim_max;
  int /*<<< orphan*/ rlim_cur;
};
struct bpf_insn {
  int dummy;
};
typedef enum bpf_prog_type { ____Placeholder_bpf_prog_type } bpf_prog_type;
typedef int /*<<< orphan*/ attr;

/* Variables and functions */
int BPF_MAXINSNS;
int /*<<< orphan*/ BPF_PROG_LOAD;
scalar_t__ EINVAL;
scalar_t__ ENOSPC;
scalar_t__ EPERM;
int /*<<< orphan*/ RLIMIT_MEMLOCK;
int /*<<< orphan*/ RLIM_INFINITY;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ getrlimit(int /*<<< orphan*/, struct rlimit *);
char *malloc(unsigned int);
int /*<<< orphan*/ memset(union bpf_attr *, int /*<<< orphan*/, int);
void *ptr_to_u64(char *);
scalar_t__ setrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int syscall(int, int /*<<< orphan*/, union bpf_attr *, int);
int bpf_prog_load(enum bpf_prog_type prog_type, const struct bpf_insn *insns,
                  int prog_len, const char *license, unsigned kern_version,
                  char *log_buf, unsigned log_buf_size) {
  union bpf_attr attr;
  char *bpf_log_buffer = NULL;
  unsigned buffer_size = 0;
  int ret = 0;
  memset(&attr, 0, sizeof(attr));
  attr.prog_type = prog_type;
  attr.insns = ptr_to_u64((void *)insns);
  attr.insn_cnt = prog_len / sizeof(struct bpf_insn);
  attr.license = ptr_to_u64((void *)license);
  attr.log_buf = ptr_to_u64(log_buf);
  attr.log_size = log_buf_size;
  attr.log_level = log_buf ? 1 : 0;
  attr.kern_version = kern_version;
  if (log_buf)
    log_buf[0] = 0;
  if (attr.insn_cnt > BPF_MAXINSNS) {
    ret = -1;
    errno = EINVAL;
    fprintf(stderr,
            "bpf: %s. Program too large (%d insns), at most %d insns\n\n",
            strerror(errno), attr.insn_cnt, BPF_MAXINSNS);
    return ret;
  }
  ret = syscall(321, BPF_PROG_LOAD, &attr, sizeof(attr));
  if (ret < 0 && errno == EPERM) {
    struct rlimit rl = {};
    if (getrlimit(RLIMIT_MEMLOCK, &rl) == 0) {
      rl.rlim_max = RLIM_INFINITY;
      rl.rlim_cur = rl.rlim_max;
      if (setrlimit(RLIMIT_MEMLOCK, &rl) == 0)
        ret = syscall(321, BPF_PROG_LOAD, &attr, sizeof(attr));
    }
  }
  if (ret < 0 && !log_buf) {
    buffer_size = 65536;
    for (;;) {
      bpf_log_buffer = malloc(buffer_size);
      if (!bpf_log_buffer) {
        fprintf(stderr,
                "bpf: buffer log memory allocation failed for error %s\n\n",
                strerror(errno));
        return ret;
      }
      bpf_log_buffer[0] = 0;
      attr.log_buf = ptr_to_u64(bpf_log_buffer);
      attr.log_size = buffer_size;
      attr.log_level = bpf_log_buffer ? 1 : 0;
      ret = syscall(321, BPF_PROG_LOAD, &attr, sizeof(attr));
      if (ret < 0 && errno == ENOSPC) {
        free(bpf_log_buffer);
        bpf_log_buffer = NULL;
        buffer_size <<= 1;
      } else {
        break;
      }
    }
    fprintf(stderr, "bpf: %s\n%s\n", strerror(errno), bpf_log_buffer);
    free(bpf_log_buffer);
  }
  return ret;
}


x86 assembly (clang, -O0):
<bpf_prog_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9,-0x30(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
movslq -0x14(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1242 <bpf_prog_load+0xb2>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%eax
mov    0x2d9c(%rip),%rcx
cmp    (%rcx),%eax
jle    12b6 <bpf_prog_load+0x126>
movl   $0xffffffff,-0x48(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%rcx
mov    0x2d54(%rip),%rax
mov    %rcx,(%rax)
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
mov    -0x38(%rbp),%ecx
mov    0x2d4e(%rip),%rax
mov    (%rax),%r8d
lea    0xd5c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14c6 <bpf_prog_load+0x336>
mov    0x2d23(%rip),%rax
mov    (%rax),%esi
mov    $0x141,%edi
lea    -0x38(%rbp),%rdx
mov    $0x8,%ecx
call   1070 <syscall@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    137c <bpf_prog_load+0x1ec>
mov    0x2cda(%rip),%rax
mov    (%rax),%rax
mov    0x2ca8(%rip),%rcx
cmp    (%rcx),%rax
jne    137c <bpf_prog_load+0x1ec>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   10a0 <getrlimit@plt>
cmp    $0x0,%rax
jne    1377 <bpf_prog_load+0x1e7>
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
call   1090 <setrlimit@plt>
cmp    $0x0,%rax
jne    1372 <bpf_prog_load+0x1e2>
mov    0x2c86(%rip),%rax
mov    (%rax),%esi
mov    $0x141,%edi
lea    -0x38(%rbp),%rdx
mov    $0x8,%ecx
call   1070 <syscall@plt>
mov    %eax,-0x48(%rbp)
jmp    1377 <bpf_prog_load+0x1e7>
jmp    137c <bpf_prog_load+0x1ec>
cmpl   $0x0,-0x48(%rbp)
jge    14c0 <bpf_prog_load+0x330>
cmpq   $0x0,-0x30(%rbp)
jne    14c0 <bpf_prog_load+0x330>
movl   $0x10000,-0x44(%rbp)
mov    -0x44(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    13e9 <bpf_prog_load+0x259>
mov    0x2c12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2bfe(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    14c6 <bpf_prog_load+0x336>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    -0x44(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    0x2bc1(%rip),%rax
mov    (%rax),%esi
mov    $0x141,%edi
lea    -0x38(%rbp),%rdx
mov    $0x8,%ecx
call   1070 <syscall@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    147a <bpf_prog_load+0x2ea>
mov    0x2b78(%rip),%rax
mov    (%rax),%rax
mov    0x2b5e(%rip),%rcx
cmp    (%rcx),%rax
jne    147a <bpf_prog_load+0x2ea>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x40(%rbp)
mov    -0x44(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    147f <bpf_prog_load+0x2ef>
jmp    1484 <bpf_prog_load+0x2f4>
jmp    1398 <bpf_prog_load+0x208>
mov    0x2b3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2b29(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
mov    -0x40(%rbp),%rcx
lea    0xbc2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog_load>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,%r14
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%r13
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    %ebx,0x8(%rsp)
mov    %r13,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x8(%rsp)
sar    $0x2,%ebp
mov    %ebp,0x8(%rsp)
mov    %r15,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x8(%rsp)
mov    %r12d,0x8(%rsp)
test   %r14,%r14
je     11ff <bpf_prog_load+0x6f>
movb   $0x0,(%r14)
mov    0x2de2(%rip),%rbp
cmp    %r12d,0x0(%rbp)
jge    1251 <bpf_prog_load+0xc1>
mov    0x2da5(%rip),%rax
mov    (%rax),%rdi
mov    0x2da3(%rip),%rax
mov    %rdi,(%rax)
mov    0x2da1(%rip),%rax
mov    (%rax),%ebx
call   10b0 <strerror@plt>
mov    0x8(%rsp),%ecx
mov    0x0(%rbp),%r8d
lea    0xdc3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r15d
jmp    1276 <bpf_prog_load+0xe6>
mov    0x2d88(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0x8(%rsp),%rdx
mov    $0x141,%edi
mov    $0x8,%ecx
call   1070 <syscall@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1288 <bpf_prog_load+0xf8>
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d31(%rip),%rax
mov    (%rax),%rax
mov    0x2cff(%rip),%rcx
cmp    (%rcx),%rax
jne    12fb <bpf_prog_load+0x16b>
movq   $0x0,0x10(%rsp)
mov    0x2d2a(%rip),%rbx
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   10a0 <getrlimit@plt>
test   %rax,%rax
jne    12fb <bpf_prog_load+0x16b>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    %eax,0x14(%rsp)
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1090 <setrlimit@plt>
test   %rax,%rax
jne    12fb <bpf_prog_load+0x16b>
mov    0x0(%rbp),%esi
lea    0x8(%rsp),%rdx
mov    $0x141,%edi
mov    $0x8,%ecx
call   1070 <syscall@plt>
mov    %eax,%r15d
test   %r14,%r14
jne    1276 <bpf_prog_load+0xe6>
test   %r15d,%r15d
jns    1276 <bpf_prog_load+0xe6>
mov    $0x10000,%ebp
mov    $0x10000,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1396 <bpf_prog_load+0x206>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
mov    0x2c80(%rip),%r13
movb   $0x0,(%rbx)
mov    %rbx,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x8(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2c91(%rip),%rax
mov    (%rax),%esi
mov    $0x141,%edi
mov    %r14,%rdx
mov    $0x8,%ecx
call   1070 <syscall@plt>
mov    %eax,%r15d
mov    0x2c53(%rip),%rax
mov    (%rax),%r12
test   %r15d,%r15d
jns    13c9 <bpf_prog_load+0x239>
cmp    0x0(%r13),%r12
jne    13c9 <bpf_prog_load+0x239>
mov    %rbx,%rdi
call   1030 <free@plt>
add    %ebp,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1330 <bpf_prog_load+0x1a0>
jmp    13a0 <bpf_prog_load+0x210>
mov    0x2c23(%rip),%rax
mov    (%rax),%r12
mov    0x2c21(%rip),%rax
mov    (%rax),%ebx
mov    %r12,%rdi
call   10b0 <strerror@plt>
lea    0xc82(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1276 <bpf_prog_load+0xe6>
mov    0x2bf8(%rip),%rax
mov    (%rax),%ebp
mov    %r12,%rdi
call   10b0 <strerror@plt>
lea    0xc91(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1276 <bpf_prog_load+0xe6>

LLVM IR (-O0):
%struct.bpf_insn = type { i32 }
%union.bpf_attr = type { i8* }
%struct.rlimit = type { i32, i32 }
@BPF_MAXINSNS = global i32 0
@EINVAL = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str = [58 x i8] c"bpf: %s. Program too large (%d insns), at most %d insns\0A\0A\00"
@BPF_PROG_LOAD = global i32 0
@EPERM = global i64 0
@RLIMIT_MEMLOCK = global i32 0
@RLIM_INFINITY = global i32 0
@.str.1 = [56 x i8] c"bpf: buffer log memory allocation failed for error %s\0A\0A\00"
@ENOSPC = global i64 0
@.str.2 = [12 x i8] c"bpf: %s\0A%s\0A\00"
define i32 @bpf_prog_load(i32 %0, %struct.bpf_insn* %1, i32 %2, i8* %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.bpf_insn*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca %union.bpf_attr
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i32
%20 = alloca %struct.rlimit
store i32 %0, i32* %9
store %struct.bpf_insn* %1, %struct.bpf_insn** %10
store i32 %2, i32* %11
store i8* %3, i8** %12
store i32 %4, i32* %13
store i8* %5, i8** %14
store i32 %6, i32* %15
store i8* null, i8** %17
store i32 0, i32* %18
store i32 0, i32* %19
%21 = call i32 @memset(%union.bpf_attr* %16, i32 0, i32 8)
%22 = load i32, i32* %9
%23 = bitcast %union.bpf_attr* %16 to i32*
store i32 %22, i32* %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* %16 to i8**
store i8* %26, i8** %27
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = udiv i64 %29, 4
%31 = trunc i64 %30 to i32
%32 = bitcast %union.bpf_attr* %16 to i32*
store i32 %31, i32* %32
%33 = load i8*, i8** %12
%34 = call i8* @ptr_to_u64(i8* %33)
%35 = bitcast %union.bpf_attr* %16 to i8**
store i8* %34, i8** %35
%36 = load i8*, i8** %14
%37 = call i8* @ptr_to_u64(i8* %36)
%38 = bitcast %union.bpf_attr* %16 to i8**
store i8* %37, i8** %38
%39 = load i32, i32* %15
%40 = bitcast %union.bpf_attr* %16 to i32*
store i32 %39, i32* %40
%41 = load i8*, i8** %14
%42 = icmp ne i8* %41, null
%43 = zext i1 %42 to i64
%44 = select i1 %42, i32 1, i32 0
%45 = bitcast %union.bpf_attr* %16 to i32*
store i32 %44, i32* %45
%46 = load i32, i32* %13
%47 = bitcast %union.bpf_attr* %16 to i32*
store i32 %46, i32* %47
%48 = load i8*, i8** %14
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %7
%51 = load i8*, i8** %14
%52 = getelementptr inbounds i8, i8* %51, i64 0
store i8 0, i8* %52
br label %53
53: ; preds = %50, %7
%54 = bitcast %union.bpf_attr* %16 to i32*
%55 = load i32, i32* %54
%56 = load i32, i32* @BPF_MAXINSNS
%57 = icmp sgt i32 %55, %56
br i1 %57, label %58, label %68
58: ; preds = %53
store i32 -1, i32* %19
%59 = load i64, i64* @EINVAL
store i64 %59, i64* @errno
%60 = load i32, i32* @stderr
%61 = load i64, i64* @errno
%62 = call i8* @strerror(i64 %61)
%63 = bitcast %union.bpf_attr* %16 to i32*
%64 = load i32, i32* %63
%65 = load i32, i32* @BPF_MAXINSNS
%66 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %62, i32 %64, i32 %65)
%67 = load i32, i32* %19
store i32 %67, i32* %8
br label %152
68: ; preds = %53
%69 = load i32, i32* @BPF_PROG_LOAD
%70 = call i32 @syscall(i32 321, i32 %69, %union.bpf_attr* %16, i32 8)
store i32 %70, i32* %19
%71 = load i32, i32* %19
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %96
73: ; preds = %68
%74 = load i64, i64* @errno
%75 = load i64, i64* @EPERM
%76 = icmp eq i64 %74, %75
br i1 %76, label %77, label %96
77: ; preds = %73
%78 = bitcast %struct.rlimit* %20 to i8*
%79 = load i32, i32* @RLIMIT_MEMLOCK
%80 = call i64 @getrlimit(i32 %79, %struct.rlimit* %20)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %95
82: ; preds = %77
%83 = load i32, i32* @RLIM_INFINITY
%84 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %20, i32 0, i32 0
store i32 %83, i32* %84
%85 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %20, i32 0, i32 0
%86 = load i32, i32* %85
%87 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %20, i32 0, i32 1
store i32 %86, i32* %87
%88 = load i32, i32* @RLIMIT_MEMLOCK
%89 = call i64 @setrlimit(i32 %88, %struct.rlimit* %20)
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %82
%92 = load i32, i32* @BPF_PROG_LOAD
%93 = call i32 @syscall(i32 321, i32 %92, %union.bpf_attr* %16, i32 8)
store i32 %93, i32* %19
br label %94
94: ; preds = %91, %82
br label %95
95: ; preds = %94, %77
br label %96
96: ; preds = %95, %73, %68
%97 = load i32, i32* %19
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %150
99: ; preds = %96
%100 = load i8*, i8** %14
%101 = icmp ne i8* %100, null
br i1 %101, label %150, label %102
102: ; preds = %99
store i32 65536, i32* %18
br label %103
103: ; preds = %141, %102
%104 = load i32, i32* %18
%105 = call i8* @malloc(i32 %104)
store i8* %105, i8** %17
%106 = load i8*, i8** %17
%107 = icmp ne i8* %106, null
br i1 %107, label %114, label %108
108: ; preds = %103
%109 = load i32, i32* @stderr
%110 = load i64, i64* @errno
%111 = call i8* @strerror(i64 %110)
%112 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %111)
%113 = load i32, i32* %19
store i32 %113, i32* %8
br label %152
114: ; preds = %103
%115 = load i8*, i8** %17
%116 = getelementptr inbounds i8, i8* %115, i64 0
store i8 0, i8* %116
%117 = load i8*, i8** %17
%118 = call i8* @ptr_to_u64(i8* %117)
%119 = bitcast %union.bpf_attr* %16 to i8**
store i8* %118, i8** %119
%120 = load i32, i32* %18
%121 = bitcast %union.bpf_attr* %16 to i32*
store i32 %120, i32* %121
%122 = load i8*, i8** %17
%123 = icmp ne i8* %122, null
%124 = zext i1 %123 to i64
%125 = select i1 %123, i32 1, i32 0
%126 = bitcast %union.bpf_attr* %16 to i32*
store i32 %125, i32* %126
%127 = load i32, i32* @BPF_PROG_LOAD
%128 = call i32 @syscall(i32 321, i32 %127, %union.bpf_attr* %16, i32 8)
store i32 %128, i32* %19
%129 = load i32, i32* %19
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %140
131: ; preds = %114
%132 = load i64, i64* @errno
%133 = load i64, i64* @ENOSPC
%134 = icmp eq i64 %132, %133
br i1 %134, label %135, label %140
135: ; preds = %131
%136 = load i8*, i8** %17
%137 = call i32 @free(i8* %136)
store i8* null, i8** %17
%138 = load i32, i32* %18
%139 = shl i32 %138, 1
store i32 %139, i32* %18
br label %141
140: ; preds = %131, %114
br label %142
141: ; preds = %135
br label %103
142: ; preds = %140
%143 = load i32, i32* @stderr
%144 = load i64, i64* @errno
%145 = call i8* @strerror(i64 %144)
%146 = load i8*, i8** %17
%147 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %145, i8* %146)
%148 = load i8*, i8** %17
%149 = call i32 @free(i8* %148)
br label %150
150: ; preds = %142, %99, %96
%151 = load i32, i32* %19
store i32 %151, i32* %8
br label %152
152: ; preds = %150, %108, %58
%153 = load i32, i32* %8
ret i32 %153
}

LLVM IR (-O2):
%struct.bpf_insn = type { i32 }
%union.bpf_attr = type { i8* }
%struct.rlimit = type { i32, i32 }
@BPF_MAXINSNS = global i32 0
@EINVAL = global i64 0
@errno = global i64 0
@stderr = global i32 0
@.str = [58 x i8] c"bpf: %s. Program too large (%d insns), at most %d insns\0A\0A\00"
@BPF_PROG_LOAD = global i32 0
@EPERM = global i64 0
@RLIMIT_MEMLOCK = global i32 0
@RLIM_INFINITY = global i32 0
@.str.1 = [56 x i8] c"bpf: buffer log memory allocation failed for error %s\0A\0A\00"
@ENOSPC = global i64 0
@.str.2 = [12 x i8] c"bpf: %s\0A%s\0A\00"
define i32 @bpf_prog_load(i32 %0, %struct.bpf_insn* %1, i32 %2, i8* %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca %union.bpf_attr
%9 = alloca i64
%10 = bitcast i64* %9 to %struct.rlimit*
%11 = bitcast %union.bpf_attr* %8 to i8*
%12 = call i32 @memset(%union.bpf_attr* %8, i32 0, i32 8)
%13 = bitcast %union.bpf_attr* %8 to i32*
store i32 %0, i32* %13
%14 = bitcast %struct.bpf_insn* %1 to i8*
%15 = call i8* @ptr_to_u64(i8* %14)
%16 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %8, i64 0, i32 0
store i8* %15, i8** %16
%17 = ashr i32 %2, 2
store i32 %17, i32* %13
%18 = call i8* @ptr_to_u64(i8* %3)
store i8* %18, i8** %16
%19 = call i8* @ptr_to_u64(i8* %5)
store i8* %19, i8** %16
%20 = icmp ne i8* %5, null
store i32 %4, i32* %13
br i1 %20, label %21, label %22
21: ; preds = %7
store i8 0, i8* %5
br label %22
22: ; preds = %21, %7
%23 = load i32, i32* @BPF_MAXINSNS
%24 = icmp slt i32 %23, %4
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i64, i64* @EINVAL
store i64 %26, i64* @errno
%27 = load i32, i32* @stderr
%28 = call i8* @strerror(i64 %26)
%29 = load i32, i32* %13
%30 = load i32, i32* @BPF_MAXINSNS
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i8* %28, i32 %29, i32 %30)
br label %93
32: ; preds = %22
%33 = load i32, i32* @BPF_PROG_LOAD
%34 = call i32 @syscall(i32 321, i32 %33, %union.bpf_attr* %8, i32 8)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %93
36: ; preds = %32
%37 = load i64, i64* @errno
%38 = load i64, i64* @EPERM
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %57
40: ; preds = %36
%41 = bitcast i64* %9 to i8*
store i64 0, i64* %9
%42 = load i32, i32* @RLIMIT_MEMLOCK
%43 = call i64 @getrlimit(i32 %42, %struct.rlimit* %10)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %55
45: ; preds = %40
%46 = load i32, i32* @RLIM_INFINITY
%47 = bitcast i64* %9 to i32*
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %10, i64 0, i32 1
store i32 %46, i32* %48
%49 = load i32, i32* @RLIMIT_MEMLOCK
%50 = call i64 @setrlimit(i32 %49, %struct.rlimit* %10)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %45
%53 = load i32, i32* @BPF_PROG_LOAD
%54 = call i32 @syscall(i32 321, i32 %53, %union.bpf_attr* %8, i32 8)
br label %55
55: ; preds = %45, %52, %40
%56 = phi i32 [ %54, %52 ], [ %34, %45 ], [ %34, %40 ]
br label %57
57: ; preds = %55, %36
%58 = phi i32 [ %56, %55 ], [ %34, %36 ]
%59 = icmp sgt i32 %58, -1
%60 = or i1 %20, %59
br i1 %60, label %93, label %61
61: ; preds = %57
%62 = call dereferenceable_or_null(65536) i8* @malloc(i32 65536)
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %72
64: ; preds = %61
%65 = load i64, i64* @errno
br label %66
66: ; preds = %83, %64
%67 = phi i64 [ %65, %64 ], [ %79, %83 ]
%68 = phi i32 [ %58, %64 ], [ %77, %83 ]
%69 = load i32, i32* @stderr
%70 = call i8* @strerror(i64 %67)
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %70)
br label %93
72: ; preds = %61, %83
%73 = phi i8* [ %86, %83 ], [ %62, %61 ]
%74 = phi i32 [ %85, %83 ], [ 65536, %61 ]
store i8 0, i8* %73
%75 = call i8* @ptr_to_u64(i8* %73)
store i8* %75, i8** %16
store i32 1, i32* %13
%76 = load i32, i32* @BPF_PROG_LOAD
%77 = call i32 @syscall(i32 321, i32 %76, %union.bpf_attr* %8, i32 8)
%78 = icmp slt i32 %77, 0
%79 = load i64, i64* @errno
%80 = load i64, i64* @ENOSPC
%81 = icmp eq i64 %79, %80
%82 = select i1 %78, i1 %81, i1 false
br i1 %82, label %83, label %88
83: ; preds = %72
%84 = call i32 @free(i8* %73)
%85 = shl i32 %74, 1
%86 = call i8* @malloc(i32 %85)
%87 = icmp eq i8* %86, null
br i1 %87, label %66, label %72
88: ; preds = %72
%89 = load i32, i32* @stderr
%90 = call i8* @strerror(i64 %79)
%91 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %90, i8* %73)
%92 = call i32 @free(i8* %73)
br label %93
93: ; preds = %32, %57, %88, %66, %25
%94 = phi i32 [ -1, %25 ], [ %68, %66 ], [ %58, %57 ], [ %77, %88 ], [ %34, %32 ]
ret i32 %94
}