#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 /*<<< orphan*/ config2;
  int /*<<< orphan*/ config1;
  int /*<<< orphan*/ config;
};

/* Variables and functions */
int /*<<< orphan*/ __NR_perf_event_open;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ resolve_event(char *, struct perf_event_attr *);
scalar_t__ syscall(int /*<<< orphan*/, struct perf_event_attr *,
                   int /*<<< orphan*/, int, int, int /*<<< orphan*/);
int main(int ac, char **av) {
  while (*++av) {
    struct perf_event_attr attr;
    resolve_event(*av, &attr);
    printf("config %llu config1 %llu config2 %llu\n", attr.config, attr.config1,
           attr.config2);
    if (syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0) < 0)
      perror("perf_event_open");
  }
  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)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
cmpq   $0x0,0x8(%rax)
je     11d1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <resolve_event@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edx
mov    %r8d,%ecx
call   1050 <syscall@plt>
cmp    $0x0,%rax
jge    11cc <main+0x8c>
lea    0xe60(%rip),%rdi
call   1060 <perror@plt>
jmp    1156 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     11d2 <main+0x92>
mov    %rsi,%rbx
add    $0x10,%rbx
mov    %rsp,%r14
lea    0xe99(%rip),%r15
mov    0x2e72(%rip),%r13
lea    0xeb2(%rip),%r12
jmp    118c <main+0x4c>
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
je     11d2 <main+0x92>
mov    %r14,%rsi
call   1030 <resolve_event@plt>
mov    0x8(%rsp),%esi
mov    (%rsp),%ecx
mov    0x4(%rsp),%edx
mov    %r15,%rdi
call   1040 <printf@plt>
mov    0x0(%r13),%edi
mov    %r14,%rsi
xor    %edx,%edx
mov    $0xffffffff,%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1050 <syscall@plt>
test   %rax,%rax
jns    1180 <main+0x40>
mov    %r12,%rdi
call   1060 <perror@plt>
jmp    1180 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.perf_event_attr = type { i32, i32, i32 }
@.str = [39 x i8] c"config %llu config1 %llu config2 %llu\0A\00"
@__NR_perf_event_open = global i32 0
@.str.1 = [16 x i8] c"perf_event_open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.perf_event_attr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %28, %2
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i32 1
store i8** %9, i8*** %5
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %29
12: ; preds = %7
%13 = load i8**, i8*** %5
%14 = load i8*, i8** %13
%15 = call i32 @resolve_event(i8* %14, %struct.perf_event_attr* %6)
%16 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %6, i32 0, i32 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %19, i32 %21)
%23 = load i32, i32* @__NR_perf_event_open
%24 = call i64 @syscall(i32 %23, %struct.perf_event_attr* %6, i32 0, i32 -1, i32 -1, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %12
%27 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %12
br label %7
29: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32, i32, i32 }
@.str = [39 x i8] c"config %llu config1 %llu config2 %llu\0A\00"
@__NR_perf_event_open = global i32 0
@.str.1 = [16 x i8] c"perf_event_open\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.perf_event_attr
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %29, label %7
7: ; preds = %2
%8 = bitcast %struct.perf_event_attr* %3 to i8*
%9 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 2
%10 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 1
%11 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %3, i64 0, i32 0
br label %12
12: ; preds = %7, %25
%13 = phi i8* [ %5, %7 ], [ %27, %25 ]
%14 = phi i8** [ %4, %7 ], [ %26, %25 ]
%15 = call i32 @resolve_event(i8* %13, %struct.perf_event_attr* %3)
%16 = load i32, i32* %9
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17, i32 %18)
%20 = load i32, i32* @__NR_perf_event_open
%21 = call i64 @syscall(i32 %20, %struct.perf_event_attr* %3, i32 0, i32 -1, i32 -1, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %12
%26 = getelementptr inbounds i8*, i8** %14, i64 1
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %12
29: ; preds = %25, %2
ret i32 0
}