#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 config;
};

/* Variables and functions */
int /*<<< orphan*/ resolve_event(char *, struct perf_event_attr *);
unsigned mem_loads_event(void) {
  struct perf_event_attr attr;
  if (!resolve_event("MEM_INST_RETIRED.LOAD_LATENCY_ABOVE_THRESHOLD_0",
                     &attr) ||
      !resolve_event("MEM_TRANS_RETIRED.LOAD_LATENCY_GT_4", &attr))
    return attr.config;
  return -1;
}


x86 assembly (clang, -O0):
<mem_loads_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xee1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <resolve_event@plt>
cmp    $0x0,%eax
je     114a <mem_loads_event+0x3a>
lea    0xef8(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1030 <resolve_event@plt>
cmp    $0x0,%eax
jne    1155 <mem_loads_event+0x45>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    115c <mem_loads_event+0x4c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_loads_event>:
push   %rax
lea    0xee8(%rip),%rdi
mov    %rsp,%rsi
call   1030 <resolve_event@plt>
test   %eax,%eax
je     1140 <mem_loads_event+0x30>
lea    0xf05(%rip),%rdi
mov    %rsp,%rsi
call   1030 <resolve_event@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
je     1140 <mem_loads_event+0x30>
pop    %rcx
ret
mov    (%rsp),%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.perf_event_attr = type { i32 }
@.str = [48 x i8] c"MEM_INST_RETIRED.LOAD_LATENCY_ABOVE_THRESHOLD_0\00"
@.str.1 = [36 x i8] c"MEM_TRANS_RETIRED.LOAD_LATENCY_GT_4\00"
define i32 @mem_loads_event() {
%1 = alloca i32
%2 = alloca %struct.perf_event_attr
%3 = call i32 @resolve_event(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), %struct.perf_event_attr* %2)
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @resolve_event(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %struct.perf_event_attr* %2)
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %0
%9 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %2, i32 0, i32 0
%10 = load i32, i32* %9
store i32 %10, i32* %1
br label %12
11: ; preds = %5
store i32 -1, i32* %1
br label %12
12: ; preds = %11, %8
%13 = load i32, i32* %1
ret i32 %13
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32 }
@.str = [48 x i8] c"MEM_INST_RETIRED.LOAD_LATENCY_ABOVE_THRESHOLD_0\00"
@.str.1 = [36 x i8] c"MEM_TRANS_RETIRED.LOAD_LATENCY_GT_4\00"
define i32 @mem_loads_event() {
%1 = alloca %struct.perf_event_attr
%2 = bitcast %struct.perf_event_attr* %1 to i8*
%3 = call i32 @resolve_event(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), %struct.perf_event_attr* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @resolve_event(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %struct.perf_event_attr* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5, %0
%9 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %1, i64 0, i32 0
%10 = load i32, i32* %9
br label %11
11: ; preds = %5, %8
%12 = phi i32 [ %10, %8 ], [ -1, %5 ]
ret i32 %12
}