#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, unsigned int, unsigned int, unsigned int,
                           unsigned int);
int /*<<< orphan*/ __cpuid_count(int, int /*<<< orphan*/, unsigned int,
                                 unsigned int, unsigned int, unsigned int);
unsigned int __get_cpuid_max(int /*<<< orphan*/, int /*<<< orphan*/);
int simd_get_supported_features(void) {
  int result = 0;
  unsigned eax = 0, ebx = 0, ecx = 0, edx = 0;
  unsigned int max_level = __get_cpuid_max(0, 0);
  __cpuid(0, eax, ebx, ecx, edx);
  if (eax >= 1) {
    __cpuid(1, eax, ebx, ecx, edx);
  }
  if (edx & (1 << 23)) {
    result |= (1 << 1);
  }
  if (edx & (1 << 26)) {
    result |= (1 << 2);
  }
  if (ecx & (1 << 28)) {
    result |= (1 << 3);
  }
  if (max_level >= 7) {
    __cpuid_count(7, 0, eax, ebx, ecx, edx);
    if (ebx & (1 << 16)) {
      result |= (1 << 9);
    }
    if (ebx & (1 << 5)) {
      result |= (1 << 4);
    }
  }
  return (result);
}


x86 assembly (clang, -O0):
<simd_get_supported_features>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1030 <__get_cpuid_max@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
xor    %edi,%edi
call   1040 <__cpuid@plt>
cmpl   $0x1,-0x8(%rbp)
jb     119c <simd_get_supported_features+0x6c>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    $0x1,%edi
call   1040 <__cpuid@plt>
mov    -0x14(%rbp),%eax
and    $0x800000,%eax
cmp    $0x0,%eax
je     11b6 <simd_get_supported_features+0x86>
mov    -0x4(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
and    $0x4000000,%eax
cmp    $0x0,%eax
je     11d0 <simd_get_supported_features+0xa0>
mov    -0x4(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
and    $0x10000000,%eax
cmp    $0x0,%eax
je     11ea <simd_get_supported_features+0xba>
mov    -0x4(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x7,-0x18(%rbp)
jb     1247 <simd_get_supported_features+0x117>
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    $0x7,%edi
xor    %esi,%esi
call   1050 <__cpuid_count@plt>
mov    -0xc(%rbp),%eax
and    $0x10000,%eax
cmp    $0x0,%eax
je     122a <simd_get_supported_features+0xfa>
mov    -0x4(%rbp),%eax
or     $0x200,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
je     1242 <simd_get_supported_features+0x112>
mov    -0x4(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x4(%rbp)
jmp    1247 <simd_get_supported_features+0x117>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simd_get_supported_features>:
push   %rbx
xor    %edi,%edi
xor    %esi,%esi
call   1030 <__get_cpuid_max@plt>
mov    %eax,%ebx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <__cpuid@plt>
cmp    $0x7,%ebx
jb     1167 <simd_get_supported_features+0x37>
mov    $0x7,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1050 <__cpuid_count@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @simd_get_supported_features() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i32 @__get_cpuid_max(i32 0, i32 0)
store i32 %7, i32* %6
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = call i32 @__cpuid(i32 0, i32 %8, i32 %9, i32 %10, i32 %11)
%13 = load i32, i32* %2
%14 = icmp uge i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @__cpuid(i32 1, i32 %16, i32 %17, i32 %18, i32 %19)
br label %21
21: ; preds = %15, %0
%22 = load i32, i32* %5
%23 = and i32 %22, 8388608
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %1
%27 = or i32 %26, 2
store i32 %27, i32* %1
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %5
%30 = and i32 %29, 67108864
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %1
%34 = or i32 %33, 4
store i32 %34, i32* %1
br label %35
35: ; preds = %32, %28
%36 = load i32, i32* %4
%37 = and i32 %36, 268435456
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %1
%41 = or i32 %40, 8
store i32 %41, i32* %1
br label %42
42: ; preds = %39, %35
%43 = load i32, i32* %6
%44 = icmp uge i32 %43, 7
br i1 %44, label %45, label %65
45: ; preds = %42
%46 = load i32, i32* %2
%47 = load i32, i32* %3
%48 = load i32, i32* %4
%49 = load i32, i32* %5
%50 = call i32 @__cpuid_count(i32 7, i32 0, i32 %46, i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %3
%52 = and i32 %51, 65536
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %45
%55 = load i32, i32* %1
%56 = or i32 %55, 512
store i32 %56, i32* %1
br label %57
57: ; preds = %54, %45
%58 = load i32, i32* %3
%59 = and i32 %58, 32
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load i32, i32* %1
%63 = or i32 %62, 16
store i32 %63, i32* %1
br label %64
64: ; preds = %61, %57
br label %65
65: ; preds = %64, %42
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
define i32 @simd_get_supported_features() {
%1 = tail call i32 @__get_cpuid_max(i32 0, i32 0)
%2 = tail call i32 @__cpuid(i32 0, i32 0, i32 0, i32 0, i32 0)
%3 = icmp ugt i32 %1, 6
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @__cpuid_count(i32 7, i32 0, i32 0, i32 0, i32 0, i32 0)
br label %6
6: ; preds = %4, %0
ret i32 0
}