#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*/ sigsafe_printf(char *);
int cpu_has_pku(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))) {
    do {
      if (2 <= 0)
        sigsafe_printf("cpu does not have PKU\n");
    } while (0);
    return 0;
  }
  if (!(ecx & (1 << 4))) {
    do {
      if (2 <= 0)
        sigsafe_printf("cpu does not have OSPKE\n");
    } while (0);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<cpu_has_pku>:
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    1160 <cpu_has_pku+0x50>
jmp    114f <cpu_has_pku+0x3f>
jmp    1154 <cpu_has_pku+0x44>
movl   $0x0,-0x4(%rbp)
jmp    118c <cpu_has_pku+0x7c>
mov    -0x10(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    1185 <cpu_has_pku+0x75>
jmp    1174 <cpu_has_pku+0x64>
jmp    1179 <cpu_has_pku+0x69>
movl   $0x0,-0x4(%rbp)
jmp    118c <cpu_has_pku+0x7c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_has_pku>:
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),%eax
mov    %eax,%ecx
shl    $0x1c,%ecx
shr    $0x1f,%ecx
shr    $0x4,%eax
and    %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @cpu_has_pku() {
%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 %13, label %10
10: ; preds = %0
br label %11
11: ; preds = %10
br label %12
12: ; preds = %11
store i32 0, i32* %1
br label %21
13: ; preds = %0
%14 = load i32, i32* %4
%15 = and i32 %14, 16
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
store i32 0, i32* %1
br label %21
20: ; preds = %13
store i32 1, i32* %1
br label %21
21: ; preds = %20, %19, %12
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
define i32 @cpu_has_pku() {
%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
%13 = lshr i32 %10, 4
%14 = and i32 %13, 1
%15 = select i1 %12, i32 0, i32 %14
ret i32 %15
}