#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*/ fflush(int /*<<< orphan*/ *);
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");
      fflush(NULL);
    } while (0);
    return 0;
  }
  if (!(ecx & (1 << 4))) {
    do {
      if (2 <= 0)
        sigsafe_printf("cpu does not have OSPKE\n");
      fflush(NULL);
    } 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    1174 <cpu_has_pku+0x54>
jmp    115f <cpu_has_pku+0x3f>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <cpu_has_pku+0x84>
mov    -0x10(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
jne    119d <cpu_has_pku+0x7d>
jmp    1188 <cpu_has_pku+0x68>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <fflush@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <cpu_has_pku+0x84>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_has_pku>:
push   %rbx
sub    $0x10,%rsp
movl   $0x7,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0x4(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
call   1030 <__cpuid@plt>
mov    (%rsp),%eax
not    %eax
mov    $0x1,%ebx
test   $0x18,%al
je     1162 <cpu_has_pku+0x42>
xor    %ebx,%ebx
xor    %edi,%edi
call   1040 <fflush@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
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 %14, label %10
10: ; preds = %0
br label %11
11: ; preds = %10
%12 = call i32 @fflush(i32* null)
br label %13
13: ; preds = %11
store i32 0, i32* %1
br label %23
14: ; preds = %0
%15 = load i32, i32* %4
%16 = and i32 %15, 16
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
br label %19
19: ; preds = %18
%20 = call i32 @fflush(i32* null)
br label %21
21: ; preds = %19
store i32 0, i32* %1
br label %23
22: ; preds = %14
store i32 1, i32* %1
br label %23
23: ; preds = %22, %21, %13
%24 = load i32, i32* %1
ret i32 %24
}

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, 24
%12 = icmp eq i32 %11, 24
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @fflush(i32* null)
br label %15
15: ; preds = %0, %13
%16 = phi i32 [ 0, %13 ], [ 1, %0 ]
ret i32 %16
}