#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_reader {
  int dummy;
};
struct perf_event_attr {
  int sample_type;
  int sample_period;
  int wakeup_events;
  int /*<<< orphan*/ type;
  int /*<<< orphan*/ config;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ buf;

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


x86 assembly (clang, -O0):
<bpf_attach_tracing_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
lea    -0x148(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xdd5(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x130(%rbp),%rdi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12a7 <bpf_attach_tracing_event+0xc7>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x150(%rbp)
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x154(%rbp),%edi
mov    -0x150(%rbp),%rdx
mov    %rax,%rcx
lea    0xd70(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <bpf_attach_tracing_event+0x302>
mov    -0x28(%rbp),%edi
lea    -0x130(%rbp),%rsi
mov    $0x100,%edx
call   1090 <read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    12d8 <bpf_attach_tracing_event+0xf8>
movslq -0x30(%rbp),%rax
cmp    $0x100,%rax
jb     1333 <bpf_attach_tracing_event+0x153>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x164(%rbp)
lea    -0x130(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rdx
mov    %rax,%rcx
lea    0xcfa(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <bpf_attach_tracing_event+0x302>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
movslq -0x30(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
lea    -0x130(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10c0 <strtol@plt>
mov    %eax,-0x138(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x13c(%rbp)
mov    0x2c53(%rip),%rax
mov    (%rax),%eax
mov    0x2c42(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x148(%rbp)
movl   $0x1,-0x144(%rbp)
movl   $0x1,-0x140(%rbp)
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    -0x148(%rbp),%rsi
mov    $0x8,%r9d
call   10b0 <syscall@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    141c <bpf_attach_tracing_event+0x23c>
mov    0x2be5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x174(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x170(%rbp)
mov    0x2bc3(%rip),%rax
mov    (%rax),%edi
call   1100 <strerror@plt>
mov    -0x174(%rbp),%edi
mov    -0x170(%rbp),%rdx
mov    %rax,%rcx
lea    0xc17(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <bpf_attach_tracing_event+0x302>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1030 <perf_reader_set_fd@plt>
mov    -0x18(%rbp),%rdi
mov    -0x13c(%rbp),%esi
mov    -0x148(%rbp),%edx
call   10f0 <perf_reader_mmap@plt>
cmp    $0x0,%rax
jge    1453 <bpf_attach_tracing_event+0x273>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <bpf_attach_tracing_event+0x302>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x178(%rbp)
mov    0x2b45(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%edi
mov    $0x8,%esi
call   1040 <_IOW@plt>
mov    -0x178(%rbp),%edi
mov    %eax,%esi
mov    -0x8(%rbp),%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    14a6 <bpf_attach_tracing_event+0x2c6>
lea    0xba9(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <bpf_attach_tracing_event+0x302>
mov    -0x2c(%rbp),%edi
mov    0x2b20(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    14db <bpf_attach_tracing_event+0x2fb>
lea    0xb92(%rip),%rdi
call   10e0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e2 <bpf_attach_tracing_event+0x302>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_attach_tracing_event>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %r9d,%r12d
mov    %r8d,%r13d
mov    %ecx,%r15d
mov    %rdx,0x28(%rsp)
mov    %rsi,%rbx
mov    %edi,0xc(%rsp)
lea    0xe03(%rip),%rdx
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %edx,%edx
call   10c0 <open@plt>
test   %eax,%eax
js     1285 <bpf_attach_tracing_event+0xb5>
mov    %eax,%r14d
lea    0x30(%rsp),%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1080 <read@plt>
lea    -0x100(%rax),%ecx
cmp    $0xffffff00,%ecx
ja     12af <bpf_attach_tracing_event+0xdf>
mov    0x2d66(%rip),%rax
mov    (%rax),%ebx
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xdab(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1090 <fprintf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
jmp    13ca <bpf_attach_tracing_event+0x1fa>
mov    0x2d2c(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xd63(%rip),%rsi
lea    0x30(%rsp),%rdx
mov    %ebx,%edi
jmp    13c2 <bpf_attach_tracing_event+0x1f2>
mov    %eax,%ebp
mov    %r14d,%edi
call   1070 <close@plt>
movb   $0x0,0x30(%rsp,%rbp,1)
lea    0x30(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtol@plt>
mov    %eax,0x20(%rsp)
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2ce4(%rip),%rax
mov    0x2cd5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x10(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x14(%rsp)
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
mov    $0x8,%r9d
mov    %r15d,%edx
mov    %r13d,%ecx
mov    %r12d,%r8d
call   10a0 <syscall@plt>
test   %eax,%eax
js     139f <bpf_attach_tracing_event+0x1cf>
mov    %eax,%ebp
mov    0x28(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <perf_reader_set_fd@plt>
mov    0x10(%rsp),%edx
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
call   10e0 <perf_reader_mmap@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     13cf <bpf_attach_tracing_event+0x1ff>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edx
mov    $0x24,%edi
mov    $0x8,%esi
call   1040 <_IOW@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    0xc(%rsp),%edx
call   1060 <ioctl@plt>
test   %rax,%rax
js     13e3 <bpf_attach_tracing_event+0x213>
mov    0x2c4c(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %edx,%edx
call   1060 <ioctl@plt>
test   %rax,%rax
jns    13cf <bpf_attach_tracing_event+0x1ff>
lea    0xcbf(%rip),%rdi
jmp    13ea <bpf_attach_tracing_event+0x21a>
mov    0x2c12(%rip),%rax
mov    (%rax),%ebp
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
call   10f0 <strerror@plt>
lea    0xc65(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1090 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc54(%rip),%rdi
call   10d0 <perror@plt>
jmp    13ca <bpf_attach_tracing_event+0x1fa>

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

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