#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 sample_period;
  int wakeup_events;
  int /*<<< orphan*/ sample_type;
  int /*<<< orphan*/ type;
  int /*<<< orphan*/ config;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PERF_EVENT_IOC_ENABLE;
int /*<<< orphan*/ PERF_SAMPLE_RAW;
int /*<<< orphan*/ PERF_TYPE_TRACEPOINT;
int /*<<< orphan*/ _IOW(char, int, int /*<<< orphan*/);
int /*<<< orphan*/ __NR_perf_event_open;
int /*<<< orphan*/ __u32;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int syscall(int /*<<< orphan*/, struct perf_event_attr *, int /*<<< orphan*/,
            int, int, unsigned long);
int bpf_attach_tracing_event(int progfd, const char *event_path, pid_t pid,
                             int cpu, int group_fd) {
  int efd = -1, rc = -1, pfd = -1;
  ssize_t bytes = -1;
  char buf[256];
  struct perf_event_attr attr = {};
  snprintf(buf, sizeof(buf), "%s/id", event_path);
  efd = open(buf, O_RDONLY, 0);
  if (efd < 0) {
    fprintf(stderr, "open(%s): %s\n", buf, strerror(errno));
    goto cleanup;
  }
  bytes = read(efd, buf, sizeof(buf));
  if (bytes <= 0 || bytes >= sizeof(buf)) {
    fprintf(stderr, "read(%s): %s\n", buf, strerror(errno));
    goto cleanup;
  }
  buf[bytes] = '\0';
  attr.config = strtol(buf, NULL, 0);
  attr.type = PERF_TYPE_TRACEPOINT;
  attr.sample_type = PERF_SAMPLE_RAW;
  attr.sample_period = 1;
  attr.wakeup_events = 1;
  pfd = syscall(__NR_perf_event_open, &attr, pid, cpu, group_fd, (1UL << 3));
  if (pfd < 0) {
    perror("perf_event_open");
    goto cleanup;
  }
  if (ioctl(pfd, _IOW('$', 8, __u32), progfd) < 0) {
    perror("ioctl(PERF_EVENT_IOC_SET_BPF)");
    goto cleanup;
  }
  if (ioctl(pfd, PERF_EVENT_IOC_ENABLE, 0) < 0) {
    perror("ioctl(PERF_EVENT_IOC_ENABLE)");
    goto cleanup;
  }
  rc = pfd;
  pfd = -1;
cleanup:
  if (efd >= 0)
    close(efd);
  if (pfd >= 0)
    close(pfd);
  return rc;
}


x86 assembly (clang, -O0):
<bpf_attach_tracing_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
lea    -0x148(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xdde(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rdi
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1297 <bpf_attach_tracing_event+0xd7>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rdx
mov    %rax,%rcx
lea    0xd79(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1434 <bpf_attach_tracing_event+0x274>
mov    -0x20(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    12c8 <bpf_attach_tracing_event+0x108>
movslq -0x2c(%rbp),%rax
cmp    $0x100,%rax
jb     1314 <bpf_attach_tracing_event+0x154>
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x164(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rdx
mov    %rax,%rcx
lea    0xd0a(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1434 <bpf_attach_tracing_event+0x274>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
lea    -0x130(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtol@plt>
mov    %eax,-0x138(%rbp)
mov    0x2ca9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    0x2c7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x140(%rbp)
movl   $0x1,-0x148(%rbp)
movl   $0x1,-0x144(%rbp)
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    -0x148(%rbp),%rsi
mov    $0x8,%r9d
call   10a0 <syscall@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    13ad <bpf_attach_tracing_event+0x1ed>
lea    0xc7f(%rip),%rdi
call   10d0 <perror@plt>
jmp    1434 <bpf_attach_tracing_event+0x274>
mov    -0x28(%rbp),%eax
mov    %eax,-0x168(%rbp)
mov    0x2bf3(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%edi
mov    $0x8,%esi
call   1030 <_IOW@plt>
mov    -0x168(%rbp),%edi
mov    %eax,%esi
mov    -0x4(%rbp),%edx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    13f9 <bpf_attach_tracing_event+0x239>
lea    0xc43(%rip),%rdi
call   10d0 <perror@plt>
jmp    1434 <bpf_attach_tracing_event+0x274>
mov    -0x28(%rbp),%edi
mov    0x2bcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1427 <bpf_attach_tracing_event+0x267>
lea    0xc33(%rip),%rdi
call   10d0 <perror@plt>
jmp    1434 <bpf_attach_tracing_event+0x274>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     1446 <bpf_attach_tracing_event+0x286>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x28(%rbp)
jl     1458 <bpf_attach_tracing_event+0x298>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_attach_tracing_event>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x120,%rsp
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %edx,%ebp
mov    %rsi,%rcx
mov    %edi,%r14d
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe1d(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   10b0 <open@plt>
test   %eax,%eax
js     1264 <bpf_attach_tracing_event+0xb4>
mov    %eax,%ebx
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1070 <read@plt>
lea    -0x100(%rax),%ecx
cmp    $0xffffff00,%ecx
ja     129b <bpf_attach_tracing_event+0xeb>
mov    0x2d8c(%rip),%rax
mov    (%rax),%ebp
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xdc9(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebp,%edi
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    1341 <bpf_attach_tracing_event+0x191>
mov    0x2d55(%rip),%rax
mov    (%rax),%ebx
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd84(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    1348 <bpf_attach_tracing_event+0x198>
mov    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <strtol@plt>
mov    %eax,0x10(%rsp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movabs $0x100000001,%rax
mov    %rax,(%rsp)
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x8,%r9d
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
call   1090 <syscall@plt>
test   %eax,%eax
js     135a <bpf_attach_tracing_event+0x1aa>
mov    %eax,%ebp
mov    0x2ca8(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%edi
mov    $0x8,%esi
call   1030 <_IOW@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r14d,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     136b <bpf_attach_tracing_event+0x1bb>
mov    0x2c9f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
js     1374 <bpf_attach_tracing_event+0x1c4>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc1(%rip),%rdi
call   10c0 <perror@plt>
jmp    125a <bpf_attach_tracing_event+0xaa>
lea    0xcc0(%rip),%rdi
jmp    137b <bpf_attach_tracing_event+0x1cb>
lea    0xcd5(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1291 <bpf_attach_tracing_event+0xe1>

LLVM IR (-O0):
%struct.perf_event_attr = type { i32, i32, i32, i32, i32 }
@.str = [6 x i8] c"%s/id\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"open(%s): %s\0A\00"
@errno = global i32 0
@.str.2 = [14 x i8] c"read(%s): %s\0A\00"
@PERF_TYPE_TRACEPOINT = global i32 0
@PERF_SAMPLE_RAW = global i32 0
@__NR_perf_event_open = global i32 0
@.str.3 = [16 x i8] c"perf_event_open\00"
@__u32 = global i32 0
@.str.4 = [30 x i8] c"ioctl(PERF_EVENT_IOC_SET_BPF)\00"
@PERF_EVENT_IOC_ENABLE = global i32 0
@.str.5 = [29 x i8] c"ioctl(PERF_EVENT_IOC_ENABLE)\00"
define i32 @bpf_attach_tracing_event(i32 %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [256 x i8]
%16 = alloca %struct.perf_event_attr
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32 -1, i32* %11
store i32 -1, i32* %12
store i32 -1, i32* %13
store i32 -1, i32* %14
%17 = bitcast %struct.perf_event_attr* %16 to i8*
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%19 = load i8*, i8** %7
%20 = call i32 @snprintf(i8* %18, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22, i32 0)
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %5
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
br label %88
32: ; preds = %5
%33 = load i32, i32* %11
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 256)
store i32 %35, i32* %14
%36 = load i32, i32* %14
%37 = icmp sle i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %32
%39 = load i32, i32* %14
%40 = sext i32 %39 to i64
%41 = icmp uge i64 %40, 256
br i1 %41, label %42, label %48
42: ; preds = %38, %32
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %46)
br label %88
48: ; preds = %38
%49 = load i32, i32* %14
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 %50
store i8 0, i8* %51
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%53 = call i32 @strtol(i8* %52, i32* null, i32 0)
%54 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %16, i32 0, i32 4
store i32 %53, i32* %54
%55 = load i32, i32* @PERF_TYPE_TRACEPOINT
%56 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %16, i32 0, i32 3
store i32 %55, i32* %56
%57 = load i32, i32* @PERF_SAMPLE_RAW
%58 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %16, i32 0, i32 2
store i32 %57, i32* %58
%59 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %16, i32 0, i32 0
store i32 1, i32* %59
%60 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %16, i32 0, i32 1
store i32 1, i32* %60
%61 = load i32, i32* @__NR_perf_event_open
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = load i32, i32* %10
%65 = call i32 @syscall(i32 %61, %struct.perf_event_attr* %16, i32 %62, i32 %63, i32 %64, i64 8)
store i32 %65, i32* %13
%66 = load i32, i32* %13
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %48
%69 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %88
70: ; preds = %48
%71 = load i32, i32* %13
%72 = load i32, i32* @__u32
%73 = call i32 @_IOW(i8 signext 36, i32 8, i32 %72)
%74 = load i32, i32* %6
%75 = call i64 @ioctl(i32 %71, i32 %73, i32 %74)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %70
%78 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %88
79: ; preds = %70
%80 = load i32, i32* %13
%81 = load i32, i32* @PERF_EVENT_IOC_ENABLE
%82 = call i64 @ioctl(i32 %80, i32 %81, i32 0)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
br label %88
86: ; preds = %79
%87 = load i32, i32* %13
store i32 %87, i32* %12
store i32 -1, i32* %13
br label %88
88: ; preds = %86, %84, %77, %68, %42, %26
%89 = load i32, i32* %11
%90 = icmp sge i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i32, i32* %11
%93 = call i32 @close(i32 %92)
br label %94
94: ; preds = %91, %88
%95 = load i32, i32* %13
%96 = icmp sge i32 %95, 0
br i1 %96, label %97, label %100
97: ; preds = %94
%98 = load i32, i32* %13
%99 = call i32 @close(i32 %98)
br label %100
100: ; preds = %97, %94
%101 = load i32, i32* %12
ret i32 %101
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32, i32, i32, i32, i32 }
@.str = [6 x i8] c"%s/id\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [14 x i8] c"open(%s): %s\0A\00"
@errno = global i32 0
@.str.2 = [14 x i8] c"read(%s): %s\0A\00"
@PERF_TYPE_TRACEPOINT = global i32 0
@PERF_SAMPLE_RAW = global i32 0
@__NR_perf_event_open = global i32 0
@.str.3 = [16 x i8] c"perf_event_open\00"
@__u32 = global i32 0
@.str.4 = [30 x i8] c"ioctl(PERF_EVENT_IOC_SET_BPF)\00"
@PERF_EVENT_IOC_ENABLE = global i32 0
@.str.5 = [29 x i8] c"ioctl(PERF_EVENT_IOC_ENABLE)\00"
define i32 @bpf_attach_tracing_event(i32 %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = alloca %struct.perf_event_attr
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = bitcast %struct.perf_event_attr* %7 to i8*
%10 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %8, i32 %11, i32 0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %48, label %14
14: ; preds = %5
%15 = call i32 @read(i32 %12, i8* %8, i32 256)
%16 = add i32 %15, -256
%17 = icmp ult i32 %16, -255
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %21)
br label %53
23: ; preds = %14
%24 = zext i32 %15 to i64
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @strtol(i8* nocapture %8, i32* null, i32 0)
%27 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %7, i64 0, i32 4
store i32 %26, i32* %27
%28 = load i32, i32* @PERF_TYPE_TRACEPOINT
%29 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %7, i64 0, i32 3
store i32 %28, i32* %29
%30 = load i32, i32* @PERF_SAMPLE_RAW
%31 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %7, i64 0, i32 2
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %7, i64 0, i32 0
store i32 1, i32* %32
%33 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %7, i64 0, i32 1
store i32 1, i32* %33
%34 = load i32, i32* @__NR_perf_event_open
%35 = call i32 @syscall(i32 %34, %struct.perf_event_attr* %7, i32 %2, i32 %3, i32 %4, i64 8)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %23
%38 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %53
39: ; preds = %23
%40 = load i32, i32* @__u32
%41 = call i32 @_IOW(i8 signext 36, i32 8, i32 %40)
%42 = call i64 @ioctl(i32 %35, i32 %41, i32 %0)
%43 = icmp slt i64 %42, 0
br i1 %43, label %56, label %44
44: ; preds = %39
%45 = load i32, i32* @PERF_EVENT_IOC_ENABLE
%46 = call i64 @ioctl(i32 %35, i32 %45, i32 0)
%47 = icmp slt i64 %46, 0
br i1 %47, label %56, label %53
48: ; preds = %5
%49 = load i32, i32* @stderr
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %51)
br label %61
53: ; preds = %44, %37, %18
%54 = phi i32 [ -1, %18 ], [ -1, %37 ], [ %35, %44 ]
%55 = call i32 @close(i32 %12)
br label %61
56: ; preds = %44, %39
%57 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), %39 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), %44 ]
%58 = call i32 @perror(i8* %57)
%59 = call i32 @close(i32 %12)
%60 = call i32 @close(i32 %35)
br label %61
61: ; preds = %53, %48, %56
%62 = phi i32 [ -1, %48 ], [ -1, %56 ], [ %54, %53 ]
ret i32 %62
}