#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 type;
  int config;
  int read_format;
  int pinned;
  int config1;
};

/* Variables and functions */
int /*<<< orphan*/ PERF_FLAG_FD_NO_GROUP;
int PERF_FORMAT_ID;
int PERF_FORMAT_TOTAL_TIME_ENABLED;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(struct perf_event_attr *, int /*<<< orphan*/, int);
int perf_event_open(struct perf_event_attr *, int, int, int,
                    int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd;
  static struct perf_event_attr pe;
  memset(&pe, 0, sizeof(struct perf_event_attr));
  pe.type = 6;
  pe.config = 0x2ULL;
  pe.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_ID;
  pe.pinned = 1;
  pe.config1 = 0x39ULL;
  fd = perf_event_open(&pe, -1, 5, -1, PERF_FLAG_FD_NO_GROUP);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0x2eef(%rip),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
movl   $0x6,0x2ed9(%rip)
movl   $0x2,0x2ed3(%rip)
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    0x2e5b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x2ebf(%rip)
movl   $0x1,0x2eb9(%rip)
movl   $0x39,0x2eb3(%rip)
mov    0x2e40(%rip),%rax
mov    (%rax),%r8d
lea    0x2e92(%rip),%rdi
mov    $0xffffffff,%ecx
mov    $0x5,%edx
mov    %ecx,%esi
call   1050 <perf_event_open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0x2f04(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
movabs $0x200000006,%rax
mov    %rax,0x2ee4(%rip)
mov    0x2e89(%rip),%rax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x2ed4(%rip)
movabs $0x3900000001,%rax
mov    %rax,0x2ec7(%rip)
mov    0x2e58(%rip),%rax
mov    (%rax),%r8d
mov    %rbx,%rdi
mov    $0xffffffff,%esi
mov    $0x5,%edx
mov    $0xffffffff,%ecx
call   1050 <perf_event_open@plt>
mov    %eax,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.perf_event_attr = type { i32, i32, i32, i32, i32 }
@main.pe = internal global %struct.perf_event_attr zeroinitializer
@PERF_FORMAT_TOTAL_TIME_ENABLED = global i32 0
@PERF_FORMAT_ID = global i32 0
@PERF_FLAG_FD_NO_GROUP = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @memset(%struct.perf_event_attr* @main.pe, i32 0, i32 20)
store i32 6, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i32 0, i32 0)
store i32 2, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i32 0, i32 1)
%8 = load i32, i32* @PERF_FORMAT_TOTAL_TIME_ENABLED
%9 = load i32, i32* @PERF_FORMAT_ID
%10 = or i32 %8, %9
store i32 %10, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i32 0, i32 2)
store i32 1, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i32 0, i32 3)
store i32 57, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i32 0, i32 4)
%11 = load i32, i32* @PERF_FLAG_FD_NO_GROUP
%12 = call i32 @perf_event_open(%struct.perf_event_attr* @main.pe, i32 -1, i32 5, i32 -1, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i32 @close(i32 %13)
ret i32 0
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32, i32, i32, i32, i32 }
@main.pe = internal global %struct.perf_event_attr zeroinitializer
@PERF_FORMAT_TOTAL_TIME_ENABLED = global i32 0
@PERF_FORMAT_ID = global i32 0
@PERF_FLAG_FD_NO_GROUP = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @memset(%struct.perf_event_attr* @main.pe, i32 0, i32 20)
store i32 6, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i64 0, i32 0)
store i32 2, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i64 0, i32 1)
%4 = load i32, i32* @PERF_FORMAT_TOTAL_TIME_ENABLED
%5 = load i32, i32* @PERF_FORMAT_ID
%6 = or i32 %5, %4
store i32 %6, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i64 0, i32 2)
store i32 1, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i64 0, i32 3)
store i32 57, i32* getelementptr inbounds (%struct.perf_event_attr, %struct.perf_event_attr* @main.pe, i64 0, i32 4)
%7 = load i32, i32* @PERF_FLAG_FD_NO_GROUP
%8 = tail call i32 @perf_event_open(%struct.perf_event_attr* @main.pe, i32 -1, i32 5, i32 -1, i32 %7)
%9 = tail call i32 @close(i32 %8)
ret i32 0
}