#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 */
typedef int /*<<< orphan*/ uint64_t;
struct perf_event_attr {
  int type;
  int size;
  int disabled;
  int exclude_kernel;
  int exclude_hv;
  int /*<<< orphan*/ config;
};
typedef int /*<<< orphan*/ perf_event_attr;
typedef enum perf_type_id { ____Placeholder_perf_type_id } perf_type_id;

/* Variables and functions */
int /*<<< orphan*/ memset(struct perf_event_attr *, int /*<<< orphan*/, int);
int perf_event_open(struct perf_event_attr *, int /*<<< orphan*/, int, int,
                    int /*<<< orphan*/);
int open_performance_counter(enum perf_type_id type, uint64_t config) {
  struct perf_event_attr perf_event_attr;
  memset(&perf_event_attr, 0, sizeof(perf_event_attr));
  perf_event_attr.type = type;
  perf_event_attr.size = sizeof(perf_event_attr);
  perf_event_attr.config = config;
  perf_event_attr.disabled = 1;
  perf_event_attr.exclude_kernel = 1;
  perf_event_attr.exclude_hv = 1;
  return perf_event_open(&perf_event_attr, 0, -1, -1, 0);
}


x86 assembly (clang, -O0):
<open_performance_counter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x18,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %r8d,%r8d
mov    $0xffffffff,%ecx
mov    %r8d,%esi
mov    %ecx,%edx
call   1040 <perf_event_open@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_performance_counter>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    %ebp,0x8(%rsp)
mov    %ebx,0x1c(%rsp)
movaps 0xeb1(%rip),%xmm0
movups %xmm0,0xc(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xffffffff,%edx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <perf_event_open@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.perf_event_attr = type { i32, i32, i32, i32, i32, i32 }
define i32 @open_performance_counter(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.perf_event_attr
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32 @memset(%struct.perf_event_attr* %5, i32 0, i32 24)
%7 = load i32, i32* %3
%8 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 1
store i32 24, i32* %9
%10 = load i32, i32* %4
%11 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 5
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 2
store i32 1, i32* %12
%13 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 3
store i32 1, i32* %13
%14 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %5, i32 0, i32 4
store i32 1, i32* %14
%15 = call i32 @perf_event_open(%struct.perf_event_attr* %5, i32 0, i32 -1, i32 -1, i32 0)
ret i32 %15
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32, i32, i32, i32, i32, i32 }
define i32 @open_performance_counter(i32 %0, i32 %1) {
%3 = alloca %struct.perf_event_attr
%4 = bitcast %struct.perf_event_attr* %3 to i8*
%5 = call i32 @memset(%struct.perf_event_attr* %3, i32 0, i32 24)
%6 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 0
store i32 %0, i32* %6
%7 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 1
%8 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 5
store i32 %1, i32* %8
%9 = bitcast i32* %7 to <4 x i32>*
store <4 x i32> <i32 24, i32 1, i32 1, i32 1>, <4 x i32>* %9
%10 = call i32 @perf_event_open(%struct.perf_event_attr* %3, i32 0, i32 -1, i32 -1, i32 0)
ret i32 %10
}