#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 */

/* Variables and functions */
int /*<<< orphan*/ __cpuid(unsigned int *, unsigned int *, unsigned int *,
                           unsigned int *);
int /*<<< orphan*/ dprintf2(char *);
int cpu_has_pkeys(void) {
  unsigned int eax;
  unsigned int ebx;
  unsigned int ecx;
  unsigned int edx;
  eax = 0x7;
  ecx = 0x0;
  __cpuid(&eax, &ebx, &ecx, &edx);
  if (!(ecx & (1 << 3))) {
    dprintf2("cpu does not have PKU\n");
    return 0;
  }
  if (!(ecx & (1 << 4))) {
    dprintf2("cpu does not have OSPKE\n");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<cpu_has_pkeys>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x7,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
call   1030 <__cpuid@plt>
mov    -0x10(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
jne    1172 <cpu_has_pkeys+0x52>
lea    0xe9f(%rip),%rdi
call   1040 <dprintf2@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <cpu_has_pkeys+0x80>
mov    -0x10(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    1199 <cpu_has_pkeys+0x79>
lea    0xe8f(%rip),%rdi
call   1040 <dprintf2@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a0 <cpu_has_pkeys+0x80>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_has_pkeys>:
sub    $0x18,%rsp
movl   $0x7,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xc(%rsp),%rdi
lea    0x14(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1030 <__cpuid@plt>
mov    0x8(%rsp),%ecx
test   $0x8,%cl
jne    115f <cpu_has_pkeys+0x3f>
lea    0xea3(%rip),%rdi
jmp    1170 <cpu_has_pkeys+0x50>
mov    $0x1,%eax
test   $0x10,%cl
jne    1177 <cpu_has_pkeys+0x57>
lea    0xea7(%rip),%rdi
call   1040 <dprintf2@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"cpu does not have PKU\0A\00"
@.str.1 = [25 x i8] c"cpu does not have OSPKE\0A\00"
define i32 @cpu_has_pkeys() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 7, i32* %2
store i32 0, i32* %4
%6 = call i32 @__cpuid(i32* %2, i32* %3, i32* %4, i32* %5)
%7 = load i32, i32* %4
%8 = and i32 %7, 8
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @dprintf2(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %19
12: ; preds = %0
%13 = load i32, i32* %4
%14 = and i32 %13, 16
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @dprintf2(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %19
18: ; preds = %12
store i32 1, i32* %1
br label %19
19: ; preds = %18, %16, %10
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [23 x i8] c"cpu does not have PKU\0A\00"
@.str.1 = [25 x i8] c"cpu does not have OSPKE\0A\00"
define i32 @cpu_has_pkeys() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 7, i32* %1
store i32 0, i32* %3
%9 = call i32 @__cpuid(i32* %1, i32* %2, i32* %3, i32* %4)
%10 = load i32, i32* %3
%11 = and i32 %10, 8
%12 = icmp eq i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = and i32 %10, 16
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13, %0
%17 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %13 ]
%18 = call i32 @dprintf2(i8* %17)
br label %19
19: ; preds = %16, %13
%20 = phi i32 [ 1, %13 ], [ 0, %16 ]
ret i32 %20
}