#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 bpf_fd;
  int /*<<< orphan*/ info_len;
  int /*<<< orphan*/ info;
};
union bpf_attr {
  TYPE_1__ info;
};
typedef int /*<<< orphan*/ attr;
typedef int /*<<< orphan*/ __u32;

/* Variables and functions */
int /*<<< orphan*/ BPF_OBJ_GET_INFO_BY_FD;
int /*<<< orphan*/ memset(union bpf_attr *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ptr_to_u64(void *);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len) {
  union bpf_attr attr;
  int err;
  memset(&attr, 0, sizeof(attr));
  attr.info.bpf_fd = bpf_fd;
  attr.info.info_len = *info_len;
  attr.info.info = ptr_to_u64(info);
  err = sys_bpf(BPF_OBJ_GET_INFO_BY_FD, &attr, sizeof(attr));
  if (!err)
    *info_len = attr.info.info_len;
  return err;
}


x86 assembly (clang, -O0):
<bpf_obj_get_info_by_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1030 <sys_bpf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    119b <bpf_obj_get_info_by_fd+0x6b>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_obj_get_info_by_fd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    %ebp,0x8(%rsp)
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
call   1040 <ptr_to_u64@plt>
mov    %eax,0x10(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   1030 <sys_bpf@plt>
test   %eax,%eax
jne    118e <bpf_obj_get_info_by_fd+0x5e>
mov    0xc(%rsp),%ecx
mov    %ecx,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.bpf_attr = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32, i32 }
@BPF_OBJ_GET_INFO_BY_FD = global i32 0
define i32 @bpf_obj_get_info_by_fd(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %union.bpf_attr
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%9 = call i32 @memset(%union.bpf_attr* %7, i32 0, i32 12)
%10 = load i32, i32* %4
%11 = bitcast %union.bpf_attr* %7 to %struct.TYPE_2__*
%12 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32*, i32** %6
%14 = load i32, i32* %13
%15 = bitcast %union.bpf_attr* %7 to %struct.TYPE_2__*
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 1
store i32 %14, i32* %16
%17 = load i8*, i8** %5
%18 = call i32 @ptr_to_u64(i8* %17)
%19 = bitcast %union.bpf_attr* %7 to %struct.TYPE_2__*
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 2
store i32 %18, i32* %20
%21 = load i32, i32* @BPF_OBJ_GET_INFO_BY_FD
%22 = call i32 @sys_bpf(i32 %21, %union.bpf_attr* %7, i32 12)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %3
%26 = bitcast %union.bpf_attr* %7 to %struct.TYPE_2__*
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = load i32*, i32** %6
store i32 %28, i32* %29
br label %30
30: ; preds = %25, %3
%31 = load i32, i32* %8
ret i32 %31
}

LLVM IR (-O2):
%union.bpf_attr = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32, i32 }
@BPF_OBJ_GET_INFO_BY_FD = global i32 0
define i32 @bpf_obj_get_info_by_fd(i32 %0, i8* %1, i32* nocapture %2) {
%4 = alloca %union.bpf_attr
%5 = bitcast %union.bpf_attr* %4 to i8*
%6 = call i32 @memset(%union.bpf_attr* %4, i32 0, i32 12)
%7 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %4, i64 0, i32 0, i32 0
store i32 %0, i32* %7
%8 = load i32, i32* %2
%9 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %4, i64 0, i32 0, i32 1
store i32 %8, i32* %9
%10 = call i32 @ptr_to_u64(i8* %1)
%11 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %4, i64 0, i32 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @BPF_OBJ_GET_INFO_BY_FD
%13 = call i32 @sys_bpf(i32 %12, %union.bpf_attr* %4, i32 12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %9
store i32 %16, i32* %2
br label %17
17: ; preds = %15, %3
ret i32 %13
}