#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*/ check_xcr0_ymm();
int /*<<< orphan*/ run_cpuid(int, int /*<<< orphan*/, int *);
int has_AVX2() {
  int abcd[4];
  int osxsave_mask = (1 << 27);
  run_cpuid(1, 0, abcd);
  if ((abcd[2] & osxsave_mask) != osxsave_mask)
    return 0;
  if (!check_xcr0_ymm())
    return 0;
  run_cpuid(7, 0, abcd);
  if ((abcd[1] & (1 << 5)) != (1 << 5))
    return 0;
  return (1 << 5);
}


x86 assembly (clang, -O0):
<has_AVX2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x8000000,-0x24(%rbp)
lea    -0x20(%rbp),%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    -0x18(%rbp),%eax
and    -0x24(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     115a <has_AVX2+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <has_AVX2+0x88>
mov    $0x0,%al
call   1040 <check_xcr0_ymm@plt>
cmp    $0x0,%eax
jne    1176 <has_AVX2+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <has_AVX2+0x88>
lea    -0x20(%rbp),%rdx
mov    $0x7,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    -0x1c(%rbp),%eax
and    $0x20,%eax
cmp    $0x20,%eax
je     11a1 <has_AVX2+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <has_AVX2+0x88>
movl   $0x20,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_AVX2>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
mov    %rsp,%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
testb  $0x8,0xb(%rsp)
je     1160 <has_AVX2+0x40>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <check_xcr0_ymm@plt>
test   %eax,%eax
je     1160 <has_AVX2+0x40>
mov    %rsp,%rdx
mov    $0x7,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    0x4(%rsp),%ebx
and    $0x20,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @has_AVX2() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
store i32 134217728, i32* %3
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%5 = call i32 @run_cpuid(i32 1, i32 0, i32* %4)
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%7 = load i32, i32* %6
%8 = load i32, i32* %3
%9 = and i32 %7, %8
%10 = load i32, i32* %3
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 0, i32* %1
br label %26
13: ; preds = %0
%14 = call i32 (...) @check_xcr0_ymm()
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %13
store i32 0, i32* %1
br label %26
17: ; preds = %13
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%19 = call i32 @run_cpuid(i32 7, i32 0, i32* %18)
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%21 = load i32, i32* %20
%22 = and i32 %21, 32
%23 = icmp ne i32 %22, 32
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 0, i32* %1
br label %26
25: ; preds = %17
store i32 32, i32* %1
br label %26
26: ; preds = %25, %24, %16, %12
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
define i32 @has_AVX2() {
%1 = alloca [4 x i32]
%2 = bitcast [4 x i32]* %1 to i8*
%3 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
%4 = call i32 @run_cpuid(i32 1, i32 0, i32* %3)
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
%6 = load i32, i32* %5
%7 = and i32 %6, 134217728
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %0
%10 = call i32 (...) @check_xcr0_ymm()
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = call i32 @run_cpuid(i32 7, i32 0, i32* %3)
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = and i32 %15, 32
br label %17
17: ; preds = %12, %9, %0
%18 = phi i32 [ 0, %0 ], [ 0, %9 ], [ %16, %12 ]
ret i32 %18
}