#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 */
typedef union bpf_attr {
  int dummy;
} bpf_attr;

/* Variables and functions */
int /*<<< orphan*/ BPF_PROG_LOAD;
scalar_t__ EAGAIN;
scalar_t__ errno;
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, unsigned int);
int sys_bpf_prog_load(union bpf_attr *attr, unsigned int size) {
  int fd;
  do {
    fd = sys_bpf(BPF_PROG_LOAD, attr, size);
  } while (fd < 0 && errno == EAGAIN);
  return fd;
}


x86 assembly (clang, -O0):
<sys_bpf_prog_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2ec2(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <sys_bpf@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1160 <sys_bpf_prog_load+0x50>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    111f <sys_bpf_prog_load+0xf>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_bpf_prog_load>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2ec4(%rip),%r14
mov    0x2ead(%rip),%r15
mov    0x2e96(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <sys_bpf@plt>
test   %eax,%eax
jns    115a <sys_bpf_prog_load+0x4a>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1140 <sys_bpf_prog_load+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.bpf_attr = type { i32 }
@BPF_PROG_LOAD = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_bpf_prog_load(%union.bpf_attr* %0, i32 %1) {
%3 = alloca %union.bpf_attr*
%4 = alloca i32
%5 = alloca i32
store %union.bpf_attr* %0, %union.bpf_attr** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %18, %2
%7 = load i32, i32* @BPF_PROG_LOAD
%8 = load %union.bpf_attr*, %union.bpf_attr** %3
%9 = load i32, i32* %4
%10 = call i32 @sys_bpf(i32 %7, %union.bpf_attr* %8, i32 %9)
store i32 %10, i32* %5
br label %11
11: ; preds = %6
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @EAGAIN
%17 = icmp eq i64 %15, %16
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %6, label %20
20: ; preds = %18
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
%union.bpf_attr = type { i32 }
@BPF_PROG_LOAD = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_bpf_prog_load(%union.bpf_attr* %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = load i32, i32* @BPF_PROG_LOAD
%5 = tail call i32 @sys_bpf(i32 %4, %union.bpf_attr* %0, i32 %1)
%6 = icmp slt i32 %5, 0
%7 = load i64, i64* @errno
%8 = load i64, i64* @EAGAIN
%9 = icmp eq i64 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %3, label %11
11: ; preds = %3
ret i32 %5
}