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

/* Variables and functions */
int PERF_RECORD_MISC_SWITCH_OUT;
int PERF_RECORD_SWITCH;
int /*<<< orphan*/ SYS_perf_event_open;
int /*<<< orphan*/ syscall(int /*<<< orphan*/, struct perf_event_attr *,
                           int /*<<< orphan*/, int, int, int /*<<< orphan*/);
int main(void) {
  struct perf_event_attr attr = {
      .context_switch = 1,
  };
  syscall(SYS_perf_event_open, &attr, 0, -1, -1, 0);
  if (PERF_RECORD_SWITCH != 14 || PERF_RECORD_MISC_SWITCH_OUT != (1 << 13))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xedb(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %r9d,%r9d
mov    $0xffffffff,%r8d
mov    %r9d,%edx
mov    %r8d,%ecx
call   1030 <syscall@plt>
mov    0x2ea0(%rip),%rax
cmpl   $0xe,(%rax)
jne    116c <main+0x5c>
mov    0x2e68(%rip),%rax
cmpl   $0x2000,(%rax)
je     1178 <main+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <main+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x1,(%rsp)
mov    0x2ec1(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
mov    $0xffffffff,%ecx
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <syscall@plt>
mov    0x2eb0(%rip),%rax
mov    (%rax),%ecx
xor    $0xe,%ecx
mov    0x2e7c(%rip),%rax
mov    $0x2000,%edx
xor    (%rax),%edx
xor    %eax,%eax
or     %ecx,%edx
setne  %al
neg    %eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.perf_event_attr = type { i32 }
@__const.main.attr = %struct.perf_event_attr { i32 1 }
@SYS_perf_event_open = global i32 0
@PERF_RECORD_SWITCH = global i32 0
@PERF_RECORD_MISC_SWITCH_OUT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.perf_event_attr
store i32 0, i32* %1
%3 = bitcast %struct.perf_event_attr* %2 to i8*
%4 = load i32, i32* @SYS_perf_event_open
%5 = call i32 @syscall(i32 %4, %struct.perf_event_attr* %2, i32 0, i32 -1, i32 -1, i32 0)
%6 = load i32, i32* @PERF_RECORD_SWITCH
%7 = icmp ne i32 %6, 14
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @PERF_RECORD_MISC_SWITCH_OUT
%10 = icmp ne i32 %9, 8192
br i1 %10, label %11, label %12
11: ; preds = %8, %0
store i32 -1, i32* %1
br label %13
12: ; preds = %8
store i32 0, i32* %1
br label %13
13: ; preds = %12, %11
%14 = load i32, i32* %1
ret i32 %14
}

LLVM IR (-O2):
%struct.perf_event_attr = type { i32 }
@SYS_perf_event_open = global i32 0
@PERF_RECORD_SWITCH = global i32 0
@PERF_RECORD_MISC_SWITCH_OUT = global i32 0
define i32 @main() {
%1 = alloca %struct.perf_event_attr
%2 = bitcast %struct.perf_event_attr* %1 to i8*
%3 = getelementptr inbounds %struct.perf_event_attr, %struct.perf_event_attr* %1, i64 0, i32 0
store i32 1, i32* %3
%4 = load i32, i32* @SYS_perf_event_open
%5 = call i32 @syscall(i32 %4, %struct.perf_event_attr* %1, i32 0, i32 -1, i32 -1, i32 0)
%6 = load i32, i32* @PERF_RECORD_SWITCH
%7 = icmp ne i32 %6, 14
%8 = load i32, i32* @PERF_RECORD_MISC_SWITCH_OUT
%9 = icmp ne i32 %8, 8192
%10 = select i1 %7, i1 true, i1 %9
%11 = sext i1 %10 to i32
ret i32 %11
}