#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 pid;
  int fd;
  int /*<<< orphan*/ probe_addr;
  int /*<<< orphan*/ probe_offset;
  void *fd_type;
  void *prog_id;
  void *buf_len;
  int /*<<< orphan*/ buf;
  void *flags;
};
union bpf_attr {
  TYPE_1__ task_fd_query;
};
typedef int /*<<< orphan*/ attr;
typedef int /*<<< orphan*/ __u64;
typedef void *__u32;

/* Variables and functions */
int /*<<< orphan*/ BPF_TASK_FD_QUERY;
int /*<<< orphan*/ ptr_to_u64(char *);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len,
                      __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset,
                      __u64 *probe_addr) {
  union bpf_attr attr = {};
  int err;
  attr.task_fd_query.pid = pid;
  attr.task_fd_query.fd = fd;
  attr.task_fd_query.flags = flags;
  attr.task_fd_query.buf = ptr_to_u64(buf);
  attr.task_fd_query.buf_len = *buf_len;
  err = sys_bpf(BPF_TASK_FD_QUERY, &attr, sizeof(attr));
  *buf_len = attr.task_fd_query.buf_len;
  *prog_id = attr.task_fd_query.prog_id;
  *fd_type = attr.task_fd_query.fd_type;
  *probe_offset = attr.task_fd_query.probe_offset;
  *probe_addr = attr.task_fd_query.probe_addr;
  return err;
}


x86 assembly (clang, -O0):
<bpf_task_fd_query>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ptr_to_u64@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    -0x60(%rbp),%rsi
mov    $0x38,%edx
call   1030 <sys_bpf@plt>
mov    %eax,-0x64(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x50(%rbp),%rcx
mov    0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x54(%rbp),%ecx
mov    0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%ecx
mov    0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_task_fd_query>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r9,%r14
mov    %r8,%rbx
mov    0x80(%rsp),%r15
mov    0x78(%rsp),%r12
mov    0x70(%rsp),%r13
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
movups %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
mov    %edi,0x8(%rsp)
mov    %esi,0xc(%rsp)
mov    %rdx,0x38(%rsp)
mov    %rcx,%rdi
call   1040 <ptr_to_u64@plt>
mov    %eax,0x30(%rsp)
mov    (%rbx),%rax
mov    %rax,0x28(%rsp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
mov    $0x38,%edx
call   1030 <sys_bpf@plt>
mov    0x28(%rsp),%rcx
mov    %rcx,(%rbx)
mov    0x20(%rsp),%rcx
mov    %rcx,(%r14)
mov    0x18(%rsp),%rcx
mov    %rcx,0x0(%r13)
mov    0x14(%rsp),%ecx
mov    %ecx,(%r12)
mov    0x10(%rsp),%ecx
mov    %ecx,(%r15)
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%union.bpf_attr = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32, i32, i32, i32, i8*, i8*, i8*, i32, i8* }
@BPF_TASK_FD_QUERY = global i32 0
define i32 @bpf_task_fd_query(i32 %0, i32 %1, i8* %2, i8* %3, i8** nocapture %4, i8** nocapture writeonly %5, i8** nocapture writeonly %6, i32* nocapture writeonly %7, i32* nocapture writeonly %8) {
%10 = alloca %union.bpf_attr
%11 = bitcast %union.bpf_attr* %10 to i8*
%12 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 2
%13 = bitcast i32* %12 to i8*
%14 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 0
store i32 %0, i32* %14
%15 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 1
store i32 %1, i32* %15
%16 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 8
store i8* %2, i8** %16
%17 = tail call i32 @ptr_to_u64(i8* %3)
%18 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 7
store i32 %17, i32* %18
%19 = load i8*, i8** %4
%20 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 6
store i8* %19, i8** %20
%21 = load i32, i32* @BPF_TASK_FD_QUERY
%22 = call i32 @sys_bpf(i32 %21, %union.bpf_attr* %10, i32 56)
%23 = load i8*, i8** %20
store i8* %23, i8** %4
%24 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 5
%25 = load i8*, i8** %24
store i8* %25, i8** %5
%26 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 4
%27 = load i8*, i8** %26
store i8* %27, i8** %6
%28 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 3
%29 = load i32, i32* %28
store i32 %29, i32* %7
%30 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %10, i64 0, i32 0, i32 2
%31 = load i32, i32* %30
store i32 %31, i32* %8
ret i32 %22
}