#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 target_fd;
  int attach_bpf_fd;
  int attach_type;
  unsigned int attach_flags;
};
typedef enum bpf_attach_type {
  ____Placeholder_bpf_attach_type
} bpf_attach_type;
typedef int /*<<< orphan*/ attr;

/* Variables and functions */
int /*<<< orphan*/ BPF_PROG_ATTACH;
int /*<<< orphan*/ memset(union bpf_attr *, int /*<<< orphan*/, int);
int sys_bpf(int /*<<< orphan*/, union bpf_attr *, int);
int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type,
                    unsigned int flags) {
  union bpf_attr attr;
  memset(&attr, 0, sizeof(attr));
  attr.target_fd = target_fd;
  attr.attach_bpf_fd = prog_fd;
  attr.attach_type = type;
  attr.attach_flags = flags;
  return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr));
}


x86 assembly (clang, -O0):
<bpf_prog_attach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog_attach>:
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %ebx,(%rsp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <sys_bpf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.bpf_attr = type { i32 }
@BPF_PROG_ATTACH = global i32 0
define i32 @bpf_prog_attach(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %union.bpf_attr
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = call i32 @memset(%union.bpf_attr* %9, i32 0, i32 4)
%11 = load i32, i32* %6
%12 = bitcast %union.bpf_attr* %9 to i32*
store i32 %11, i32* %12
%13 = load i32, i32* %5
%14 = bitcast %union.bpf_attr* %9 to i32*
store i32 %13, i32* %14
%15 = load i32, i32* %7
%16 = bitcast %union.bpf_attr* %9 to i32*
store i32 %15, i32* %16
%17 = load i32, i32* %8
%18 = bitcast %union.bpf_attr* %9 to i32*
store i32 %17, i32* %18
%19 = load i32, i32* @BPF_PROG_ATTACH
%20 = call i32 @sys_bpf(i32 %19, %union.bpf_attr* %9, i32 4)
ret i32 %20
}

LLVM IR (-O2):
%union.bpf_attr = type { i32 }
@BPF_PROG_ATTACH = global i32 0
define i32 @bpf_prog_attach(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %union.bpf_attr
%6 = bitcast %union.bpf_attr* %5 to i8*
%7 = call i32 @memset(%union.bpf_attr* %5, i32 0, i32 4)
%8 = getelementptr inbounds %union.bpf_attr, %union.bpf_attr* %5, i64 0, i32 0
store i32 %3, i32* %8
%9 = load i32, i32* @BPF_PROG_ATTACH
%10 = call i32 @sys_bpf(i32 %9, %union.bpf_attr* %5, i32 4)
ret i32 %10
}