#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(int, int *, int *, int *, int *);
int /*<<< orphan*/ support_avx();
int /*<<< orphan*/ xgetbv(int /*<<< orphan*/, int *, int *);
int support_avx512() {
  int eax, ebx, ecx, edx;
  int ret = 0;
  if (!support_avx())
    return 0;
  cpuid(7, &eax, &ebx, &ecx, &edx);
  if ((ebx & (1 << 5)) == 0) {
    ret = 0;
  }
  if ((ebx & (1 << 31)) != 0) {
    xgetbv(0, &eax, &edx);
    if ((eax & 0xe0) == 0xe0)
      ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<support_avx512>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <support_avx@plt>
cmp    $0x0,%eax
jne    115b <support_avx512+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <support_avx512+0xa0>
mov    $0x7,%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <cpuid@plt>
mov    -0xc(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    118b <support_avx512+0x5b>
movl   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11ca <support_avx512+0x9a>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <xgetbv@plt>
mov    -0x8(%rbp),%eax
and    $0xe0,%eax
cmp    $0xe0,%eax
jne    11c5 <support_avx512+0x95>
movl   $0x1,-0x18(%rbp)
jmp    11ca <support_avx512+0x9a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<support_avx512>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <support_avx@plt>
test   %eax,%eax
je     1180 <support_avx512+0x50>
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    $0x7,%edi
call   1040 <cpuid@plt>
cmpl   $0x0,0x8(%rsp)
jns    1180 <support_avx512+0x50>
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %edi,%edi
call   1050 <xgetbv@plt>
mov    (%rsp),%eax
not    %eax
xor    %ebx,%ebx
test   $0xe0,%al
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @support_avx512() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %6
%7 = call i32 (...) @support_avx()
%8 = icmp ne i32 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %0
store i32 0, i32* %1
br label %29
10: ; preds = %0
%11 = call i32 @cpuid(i32 7, i32* %2, i32* %3, i32* %4, i32* %5)
%12 = load i32, i32* %3
%13 = and i32 %12, 32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 0, i32* %6
br label %16
16: ; preds = %15, %10
%17 = load i32, i32* %3
%18 = and i32 %17, -2147483648
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %16
%21 = call i32 @xgetbv(i32 0, i32* %2, i32* %5)
%22 = load i32, i32* %2
%23 = and i32 %22, 224
%24 = icmp eq i32 %23, 224
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %6
br label %26
26: ; preds = %25, %20
br label %27
27: ; preds = %26, %16
%28 = load i32, i32* %6
store i32 %28, i32* %1
br label %29
29: ; preds = %27, %9
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
define i32 @support_avx512() {
%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*
%9 = tail call i32 (...) @support_avx()
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %0
%12 = call i32 @cpuid(i32 7, i32* %1, i32* %2, i32* %3, i32* %4)
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, -1
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = call i32 @xgetbv(i32 0, i32* %1, i32* %4)
%17 = load i32, i32* %1
%18 = and i32 %17, 224
%19 = icmp eq i32 %18, 224
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %15, %11, %0
%22 = phi i32 [ 0, %0 ], [ 0, %11 ], [ %20, %15 ]
ret i32 %22
}