#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 scalar_t__ uint64_t;
typedef scalar_t__ uint32_t;
struct perf_event_attr {
  int inherit;
  int freq;
  scalar_t__ sample_period;
  scalar_t__ sample_freq;
  scalar_t__ config;
  scalar_t__ type;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
scalar_t__ PERF_COUNT_HW_MAX;
scalar_t__ PERF_COUNT_SW_MAX;
int /*<<< orphan*/ PERF_EVENT_IOC_ENABLE;
scalar_t__ PERF_TYPE_HARDWARE;
scalar_t__ PERF_TYPE_SOFTWARE;
int /*<<< orphan*/ _IOW(char, int, int /*<<< orphan*/);
int /*<<< orphan*/ __NR_perf_event_open;
int /*<<< orphan*/ __u32;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int syscall(int /*<<< orphan*/, struct perf_event_attr *, int /*<<< orphan*/,
            int, int, unsigned long);
int bpf_attach_perf_event(int progfd, uint32_t ev_type, uint32_t ev_config,
                          uint64_t sample_period, uint64_t sample_freq,
                          pid_t pid, int cpu, int group_fd) {
  if (ev_type != PERF_TYPE_HARDWARE && ev_type != PERF_TYPE_SOFTWARE) {
    fprintf(stderr, "Unsupported perf event type\n");
    return -1;
  }
  if ((ev_type == PERF_TYPE_HARDWARE && ev_config >= PERF_COUNT_HW_MAX) ||
      (ev_type == PERF_TYPE_SOFTWARE && ev_config >= PERF_COUNT_SW_MAX)) {
    fprintf(stderr, "Invalid perf event config\n");
    return -1;
  }
  if (!((sample_period > 0) ^ (sample_freq > 0))) {
    fprintf(stderr,
            "Exactly one of sample_period / sample_freq should be set\n");
    return -1;
  }
  struct perf_event_attr attr = {};
  attr.type = ev_type;
  attr.config = ev_config;
  attr.inherit = 1;
  if (sample_freq > 0) {
    attr.freq = 1;
    attr.sample_freq = sample_freq;
  } else {
    attr.sample_period = sample_period;
  }
  int fd = syscall(__NR_perf_event_open, &attr, pid, cpu, group_fd, (1UL << 3));
  if (fd < 0) {
    perror("perf_event_open failed");
    return -1;
  }
  if (ioctl(fd, _IOW('$', 8, __u32), progfd) != 0) {
    perror("ioctl(PERF_EVENT_IOC_SET_BPF) failed");
    close(fd);
    return -1;
  }
  if (ioctl(fd, PERF_EVENT_IOC_ENABLE, 0) != 0) {
    perror("ioctl(PERF_EVENT_IOC_ENABLE) failed");
    close(fd);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<bpf_attach_perf_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
je     11de <bpf_attach_perf_event+0x6e>
mov    -0x10(%rbp),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
je     11de <bpf_attach_perf_event+0x6e>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <bpf_attach_perf_event+0x253>
mov    -0x10(%rbp),%rax
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <bpf_attach_perf_event+0x96>
mov    -0x18(%rbp),%rax
mov    0x2deb(%rip),%rcx
cmp    (%rcx),%rax
jge    122e <bpf_attach_perf_event+0xbe>
mov    -0x10(%rbp),%rax
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%rax
jne    124f <bpf_attach_perf_event+0xdf>
mov    -0x18(%rbp),%rax
mov    0x2d93(%rip),%rcx
cmp    (%rcx),%rax
jl     124f <bpf_attach_perf_event+0xdf>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <bpf_attach_perf_event+0x253>
cmpq   $0x0,-0x20(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
cmpq   $0x0,-0x28(%rbp)
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
xor    %ecx,%eax
cmp    $0x0,%eax
jne    1296 <bpf_attach_perf_event+0x126>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <bpf_attach_perf_event+0x253>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x58(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    12dc <bpf_attach_perf_event+0x16c>
movl   $0x1,-0x54(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    12e4 <bpf_attach_perf_event+0x174>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    0x10(%rbp),%ecx
mov    0x18(%rbp),%r8d
lea    -0x58(%rbp),%rsi
mov    $0x8,%r9d
call   1080 <syscall@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    132b <bpf_attach_perf_event+0x1bb>
lea    0xd58(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <bpf_attach_perf_event+0x253>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%edi
mov    $0x8,%esi
call   1030 <_IOW@plt>
mov    -0x60(%rbp),%edi
mov    %eax,%esi
mov    -0x8(%rbp),%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1380 <bpf_attach_perf_event+0x210>
lea    0xd22(%rip),%rdi
call   1090 <perror@plt>
mov    -0x5c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <bpf_attach_perf_event+0x253>
mov    -0x5c(%rbp),%edi
mov    0x2c3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     13bd <bpf_attach_perf_event+0x24d>
lea    0xd0a(%rip),%rdi
call   1090 <perror@plt>
mov    -0x5c(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c3 <bpf_attach_perf_event+0x253>
mov    -0x5c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_attach_perf_event>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %r9d,%eax
mov    %edi,%r14d
mov    0x2e63(%rip),%rdi
mov    (%rdi),%rbp
mov    0x2e61(%rip),%rdi
mov    (%rdi),%rdi
cmp    %rsi,%rbp
je     119e <bpf_attach_perf_event+0x3e>
cmp    %rsi,%rdi
je     119e <bpf_attach_perf_event+0x3e>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
jmp    11d1 <bpf_attach_perf_event+0x71>
cmp    %rsi,%rbp
jne    11b0 <bpf_attach_perf_event+0x50>
mov    0x2e3e(%rip),%rbp
cmp    %rdx,0x0(%rbp)
jle    11c1 <bpf_attach_perf_event+0x61>
cmp    %rsi,%rdi
jne    11e6 <bpf_attach_perf_event+0x86>
mov    0x2dfc(%rip),%rdi
cmp    %rdx,(%rdi)
jg     11e6 <bpf_attach_perf_event+0x86>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %rcx,%rcx
setg   %dil
test   %r8,%r8
setg   %bl
xor    %dil,%bl
je     1236 <bpf_attach_perf_event+0xd6>
mov    0x58(%rsp),%r10d
mov    0x50(%rsp),%ebp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsi,0x20(%rsp)
mov    %rdx,0x18(%rsp)
movl   $0x1,(%rsp)
test   %r8,%r8
jle    1248 <bpf_attach_perf_event+0xe8>
movl   $0x1,0x4(%rsp)
mov    %r8,0x10(%rsp)
jmp    124d <bpf_attach_perf_event+0xed>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
jmp    11d1 <bpf_attach_perf_event+0x71>
mov    %rcx,0x8(%rsp)
mov    0x2d54(%rip),%rcx
mov    (%rcx),%edi
mov    %rsp,%rsi
mov    $0x8,%r9d
mov    %eax,%edx
mov    %ebp,%ecx
mov    %r10d,%r8d
call   1070 <syscall@plt>
test   %eax,%eax
js     12be <bpf_attach_perf_event+0x15e>
mov    %eax,%ebp
mov    0x2d38(%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   1040 <ioctl@plt>
test   %rax,%rax
jne    12cf <bpf_attach_perf_event+0x16f>
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <ioctl@plt>
test   %rax,%rax
je     11db <bpf_attach_perf_event+0x7b>
lea    0xdf2(%rip),%rdi
jmp    12d6 <bpf_attach_perf_event+0x176>
lea    0xdad(%rip),%rdi
call   1080 <perror@plt>
jmp    11d6 <bpf_attach_perf_event+0x76>
lea    0xdb3(%rip),%rdi
call   1080 <perror@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11d6 <bpf_attach_perf_event+0x76>

LLVM IR (-O0):
%struct.perf_event_attr = type { i32, i32, i64, i64, i64, i64 }
@PERF_TYPE_HARDWARE = global i64 0
@PERF_TYPE_SOFTWARE = global i64 0
@stderr = global i32 0
@.str = [29 x i8] c"Unsupported perf event type\0A\00"
@PERF_COUNT_HW_MAX = global i64 0
@PERF_COUNT_SW_MAX = global i64 0
@.str.1 = [27 x i8] c"Invalid perf event config\0A\00"
@.str.2 = [58 x i8] c"Exactly one of sample_period / sample_freq should be set\0A\00"
@__NR_perf_event_open = global i32 0
@.str.3 = [23 x i8] c"perf_event_open failed\00"
@__u32 = global i32 0
@.str.4 = [37 x i8] c"ioctl(PERF_EVENT_IOC_SET_BPF) failed\00"
@PERF_EVENT_IOC_ENABLE = global i32 0
@.str.5 = [36 x i8] c"ioctl(PERF_EVENT_IOC_ENABLE) failed\00"
define i32 @bpf_attach_perf_event(i32 %0, i64 %1, i64 %2, i64 %3, i64 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca %struct.perf_event_attr
%19 = alloca i32
store i32 %0, i32* %10
store i64 %1, i64* %11
store i64 %2, i64* %12
store i64 %3, i64* %13
store i64 %4, i64* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
%20 = load i64, i64* %11
%21 = load i64, i64* @PERF_TYPE_HARDWARE
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %8
%24 = load i64, i64* %11
%25 = load i64, i64* @PERF_TYPE_SOFTWARE
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %9
br label %109
30: ; preds = %23, %8
%31 = load i64, i64* %11
%32 = load i64, i64* @PERF_TYPE_HARDWARE
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i64, i64* %12
%36 = load i64, i64* @PERF_COUNT_HW_MAX
%37 = icmp sge i64 %35, %36
br i1 %37, label %46, label %38
38: ; preds = %34, %30
%39 = load i64, i64* %11
%40 = load i64, i64* @PERF_TYPE_SOFTWARE
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %49
42: ; preds = %38
%43 = load i64, i64* %12
%44 = load i64, i64* @PERF_COUNT_SW_MAX
%45 = icmp sge i64 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %42, %34
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %9
br label %109
49: ; preds = %42, %38
%50 = load i64, i64* %13
%51 = icmp sgt i64 %50, 0
%52 = zext i1 %51 to i32
%53 = load i64, i64* %14
%54 = icmp sgt i64 %53, 0
%55 = zext i1 %54 to i32
%56 = xor i32 %52, %55
%57 = icmp ne i32 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %49
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %9
br label %109
61: ; preds = %49
%62 = bitcast %struct.perf_event_attr* %18 to i8*
%63 = load i64, i64* %11
%64 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %18, i32 0, i32 5
store i64 %63, i64* %64
%65 = load i64, i64* %12
%66 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %18, i32 0, i32 4
store i64 %65, i64* %66
%67 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %18, i32 0, i32 0
store i32 1, i32* %67
%68 = load i64, i64* %14
%69 = icmp sgt i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %61
%71 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %18, i32 0, i32 1
store i32 1, i32* %71
%72 = load i64, i64* %14
%73 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %18, i32 0, i32 3
store i64 %72, i64* %73
br label %77
74: ; preds = %61
%75 = load i64, i64* %13
%76 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %18, i32 0, i32 2
store i64 %75, i64* %76
br label %77
77: ; preds = %74, %70
%78 = load i32, i32* @__NR_perf_event_open
%79 = load i32, i32* %15
%80 = load i32, i32* %16
%81 = load i32, i32* %17
%82 = call i32 @syscall(i32 %78, %struct.perf_event_attr* %18, i32 %79, i32 %80, i32 %81, i64 8)
store i32 %82, i32* %19
%83 = load i32, i32* %19
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %77
%86 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %9
br label %109
87: ; preds = %77
%88 = load i32, i32* %19
%89 = load i32, i32* @__u32
%90 = call i32 @_IOW(i8 signext 36, i32 8, i32 %89)
%91 = load i32, i32* %10
%92 = call i64 @ioctl(i32 %88, i32 %90, i32 %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %98
94: ; preds = %87
%95 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%96 = load i32, i32* %19
%97 = call i32 @close(i32 %96)
store i32 -1, i32* %9
br label %109
98: ; preds = %87
%99 = load i32, i32* %19
%100 = load i32, i32* @PERF_EVENT_IOC_ENABLE
%101 = call i64 @ioctl(i32 %99, i32 %100, i32 0)
%102 = icmp ne i64 %101, 0
br i1 %102, label %103, label %107
103: ; preds = %98
%104 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%105 = load i32, i32* %19
%106 = call i32 @close(i32 %105)
store i32 -1, i32* %9
br label %109
107: ; preds = %98
%108 = load i32, i32* %19
store i32 %108, i32* %9
br label %109
109: ; preds = %107, %103, %94, %85, %58, %46, %27
%110 = load i32, i32* %9
ret i32 %110
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32, i32, i64, i64, i64, i64 }
@PERF_TYPE_HARDWARE = global i64 0
@PERF_TYPE_SOFTWARE = global i64 0
@stderr = global i32 0
@.str = [29 x i8] c"Unsupported perf event type\0A\00"
@PERF_COUNT_HW_MAX = global i64 0
@PERF_COUNT_SW_MAX = global i64 0
@.str.1 = [27 x i8] c"Invalid perf event config\0A\00"
@.str.2 = [58 x i8] c"Exactly one of sample_period / sample_freq should be set\0A\00"
@__NR_perf_event_open = global i32 0
@.str.3 = [23 x i8] c"perf_event_open failed\00"
@__u32 = global i32 0
@.str.4 = [37 x i8] c"ioctl(PERF_EVENT_IOC_SET_BPF) failed\00"
@PERF_EVENT_IOC_ENABLE = global i32 0
@.str.5 = [36 x i8] c"ioctl(PERF_EVENT_IOC_ENABLE) failed\00"
define i32 @bpf_attach_perf_event(i32 %0, i64 %1, i64 %2, i64 %3, i64 %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca %struct.perf_event_attr
%10 = load i64, i64* @PERF_TYPE_HARDWARE
%11 = icmp eq i64 %10, %1
%12 = load i64, i64* @PERF_TYPE_SOFTWARE
%13 = icmp eq i64 %12, %1
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %71
18: ; preds = %8
%19 = icmp ne i64 %10, %1
%20 = load i64, i64* @PERF_COUNT_HW_MAX
%21 = icmp sgt i64 %20, %2
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = icmp ne i64 %12, %1
%25 = load i64, i64* @PERF_COUNT_SW_MAX
%26 = icmp sgt i64 %25, %2
%27 = select i1 %24, i1 true, i1 %26
br i1 %27, label %31, label %28
28: ; preds = %23, %18
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %71
31: ; preds = %23
%32 = icmp sgt i64 %3, 0
%33 = icmp sgt i64 %4, 0
%34 = xor i1 %32, %33
br i1 %34, label %38, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
br label %71
38: ; preds = %31
%39 = bitcast %struct.perf_event_attr* %9 to i8*
%40 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %9, i64 0, i32 5
store i64 %1, i64* %40
%41 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %9, i64 0, i32 4
store i64 %2, i64* %41
%42 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %9, i64 0, i32 0
store i32 1, i32* %42
br i1 %33, label %43, label %46
43: ; preds = %38
%44 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %9, i64 0, i32 1
store i32 1, i32* %44
%45 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %9, i64 0, i32 3
store i64 %4, i64* %45
br label %48
46: ; preds = %38
%47 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %9, i64 0, i32 2
store i64 %3, i64* %47
br label %48
48: ; preds = %46, %43
%49 = load i32, i32* @__NR_perf_event_open
%50 = call i32 @syscall(i32 %49, %struct.perf_event_attr* %9, i32 %5, i32 %6, i32 %7, i64 8)
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %69
54: ; preds = %48
%55 = load i32, i32* @__u32
%56 = call i32 @_IOW(i8 signext 36, i32 8, i32 %55)
%57 = call i64 @ioctl(i32 %50, i32 %56, i32 %0)
%58 = icmp eq i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %54
%60 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @close(i32 %50)
br label %69
62: ; preds = %54
%63 = load i32, i32* @PERF_EVENT_IOC_ENABLE
%64 = call i64 @ioctl(i32 %50, i32 %63, i32 0)
%65 = icmp eq i64 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %62
%67 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @close(i32 %50)
br label %69
69: ; preds = %62, %66, %59, %52
%70 = phi i32 [ -1, %52 ], [ -1, %59 ], [ -1, %66 ], [ %50, %62 ]
br label %71
71: ; preds = %69, %35, %28, %15
%72 = phi i32 [ -1, %15 ], [ -1, %28 ], [ %70, %69 ], [ -1, %35 ]
ret i32 %72
}