#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int prog_fd;
  int repeat;
  int /*<<< orphan*/ duration;
  int /*<<< orphan*/ retval;
  int /*<<< orphan*/ data_size_out;
  int /*<<< orphan*/ data_size_in;
  void *data_out;
  void *data_in;
};
union bpf_attr {
  TYPE_1__ test;
};
typedef int /*<<< orphan*/ attr;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ BPF_PROG_TEST_RUN;
int /*<<< orphan*/ bzero(union bpf_attr *, int);
void *ptr_to_u64(void *);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size,
                      void *data_out, __u32 *size_out, __u32 *retval,
                      __u32 *duration) {
  union bpf_attr attr;
  int ret;
  bzero(&attr, sizeof(attr));
  attr.test.prog_fd = prog_fd;
  attr.test.data_in = ptr_to_u64(data);
  attr.test.data_out = ptr_to_u64(data_out);
  attr.test.data_size_in = size;
  attr.test.repeat = repeat;
  ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr));
  if (size_out)
    *size_out = attr.test.data_size_out;
  if (retval)
    *retval = attr.test.retval;
  if (duration)
    *duration = attr.test.duration;
  return ret;
}


x86 assembly (clang, -O0):
<bpf_prog_test_run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x28,%esi
call   1050 <bzero@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
mov    $0x28,%edx
call   1030 <sys_bpf@plt>
mov    %eax,-0x54(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bd <bpf_prog_test_run+0x8d>
mov    -0x40(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,0x10(%rbp)
je     11d1 <bpf_prog_test_run+0xa1>
mov    -0x44(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,0x18(%rbp)
je     11e5 <bpf_prog_test_run+0xb5>
mov    -0x48(%rbp),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog_test_run>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%r13
mov    %ecx,%r15d
mov    %rdx,%rbp
mov    %esi,%r12d
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x28,%esi
call   1050 <bzero@plt>
mov    %ebx,(%rsp)
mov    %rbp,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x20(%rsp)
mov    %r13,%rdi
call   1040 <ptr_to_u64@plt>
mov    %rax,0x18(%rsp)
mov    %r15d,0x14(%rsp)
mov    %r12d,0x4(%rsp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x28,%edx
call   1030 <sys_bpf@plt>
test   %r14,%r14
je     11a5 <bpf_prog_test_run+0x75>
mov    0x10(%rsp),%ecx
mov    %ecx,(%r14)
mov    0x68(%rsp),%rcx
mov    0x60(%rsp),%rsi
test   %rsi,%rsi
je     11ba <bpf_prog_test_run+0x8a>
mov    0xc(%rsp),%edx
mov    %edx,(%rsi)
test   %rcx,%rcx
je     11c5 <bpf_prog_test_run+0x95>
mov    0x8(%rsp),%edx
mov    %edx,(%rcx)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%union.bpf_attr = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32, i32, i32, i32, i32, i8*, i8* }
@BPF_PROG_TEST_RUN = global i32 0
define i32 @bpf_prog_test_run(i32 %0, i32 %1, i8* %2, i32 %3, i8* %4, i32* writeonly %5, i32* writeonly %6, i32* writeonly %7) {
%9 = alloca %union.bpf_attr
%10 = bitcast %union.bpf_attr* %9 to i8*
%11 = call i32 @bzero(%union.bpf_attr* %9, i32 40)
%12 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 0
store i32 %0, i32* %12
%13 = tail call i8* @ptr_to_u64(i8* %2)
%14 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 7
store i8* %13, i8** %14
%15 = tail call i8* @ptr_to_u64(i8* %4)
%16 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 6
store i8* %15, i8** %16
%17 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 5
store i32 %3, i32* %17
%18 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 1
store i32 %1, i32* %18
%19 = load i32, i32* @BPF_PROG_TEST_RUN
%20 = call i32 @sys_bpf(i32 %19, %union.bpf_attr* %9, i32 40)
%21 = icmp eq i32* %5, null
br i1 %21, label %25, label %22
22: ; preds = %8
%23 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 4
%24 = load i32, i32* %23
store i32 %24, i32* %5
br label %25
25: ; preds = %22, %8
%26 = icmp eq i32* %6, null
br i1 %26, label %30, label %27
27: ; preds = %25
%28 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 3
%29 = load i32, i32* %28
store i32 %29, i32* %6
br label %30
30: ; preds = %27, %25
%31 = icmp eq i32* %7, null
br i1 %31, label %35, label %32
32: ; preds = %30
%33 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %9, i64 0, i32 0, i32 2
%34 = load i32, i32* %33
store i32 %34, i32* %7
br label %35
35: ; preds = %32, %30
ret i32 %20
}