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


x86 assembly (clang, -O0):
<support_avx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x14(%rbp)
mov    $0x1,%edi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1030 <cpuid@plt>
mov    -0xc(%rbp),%eax
and    $0x10000000,%eax
cmp    $0x0,%eax
je     11a6 <support_avx+0x86>
mov    -0xc(%rbp),%eax
and    $0x8000000,%eax
cmp    $0x0,%eax
je     11a6 <support_avx+0x86>
mov    -0xc(%rbp),%eax
and    $0x4000000,%eax
cmp    $0x0,%eax
je     11a6 <support_avx+0x86>
xor    %edi,%edi
lea    -0x4(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <xgetbv@plt>
mov    -0x4(%rbp),%eax
and    $0x6,%eax
cmp    $0x6,%eax
jne    11a1 <support_avx+0x81>
movl   $0x1,-0x14(%rbp)
jmp    11a6 <support_avx+0x86>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<support_avx>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    $0x1,%edi
call   1030 <cpuid@plt>
mov    0x10(%rsp),%ecx
not    %ecx
xor    %eax,%eax
test   $0x1c000000,%ecx
jne    1171 <support_avx+0x51>
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %edi,%edi
call   1040 <xgetbv@plt>
mov    0x8(%rsp),%ecx
not    %ecx
xor    %eax,%eax
test   $0x6,%cl
sete   %al
add    $0x18,%rsp
ret

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

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