#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 */
struct perf_event_attr {
  int size;
  int config;
  int /*<<< orphan*/ type;
};

/* Variables and functions */
int /*<<< orphan*/ PERF_TYPE_SOFTWARE;
int /*<<< orphan*/ __NR_perf_event_open;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ syscall(int /*<<< orphan*/, struct perf_event_attr *,
                           int /*<<< orphan*/, int, int, int /*<<< orphan*/);
int main(void) {
  struct perf_event_attr attr = {
      .type = PERF_TYPE_SOFTWARE,
      .size = sizeof(struct perf_event_attr),
      .config = 0x00000000ffffffff,
  };
  syscall(__NR_perf_event_open, &attr, getpid(), -1, -1, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x10(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    -0x10(%rbp),%rsi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
mov    %r8d,%ecx
call   1040 <syscall@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movabs $0xffffffff0000000c,%rax
ff ff ff
mov    %rax,(%rsp)
mov    0x2eae(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e91(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    $0xffffffff,%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <syscall@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.perf_event_attr = type { i32, i32, i32 }
@PERF_TYPE_SOFTWARE = global i32 0
@__NR_perf_event_open = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.perf_event_attr
store i32 0, i32* %1
%3 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %2, i32 0, i32 0
store i32 12, i32* %3
%4 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %2, i32 0, i32 1
store i32 -1, i32* %4
%5 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %2, i32 0, i32 2
%6 = load i32, i32* @PERF_TYPE_SOFTWARE
store i32 %6, i32* %5
%7 = load i32, i32* @__NR_perf_event_open
%8 = call i32 (...) @getpid()
%9 = call i32 @syscall(i32 %7, %struct.perf_event_attr* %2, i32 %8, i32 -1, i32 -1, i32 0)
ret i32 0
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32, i32, i32 }
@PERF_TYPE_SOFTWARE = global i32 0
@__NR_perf_event_open = global i32 0
define i32 @main() {
%1 = alloca %struct.perf_event_attr
%2 = bitcast %struct.perf_event_attr* %1 to i8*
%3 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %1, i64 0, i32 0
store i32 12, i32* %3
%4 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %1, i64 0, i32 1
store i32 -1, i32* %4
%5 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %1, i64 0, i32 2
%6 = load i32, i32* @PERF_TYPE_SOFTWARE
store i32 %6, i32* %5
%7 = load i32, i32* @__NR_perf_event_open
%8 = tail call i32 (...) @getpid()
%9 = call i32 @syscall(i32 %7, %struct.perf_event_attr* %1, i32 %8, i32 -1, i32 -1, i32 0)
ret i32 0
}