#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ check_xcr0_ymm();
int /*<<< orphan*/ run_cpuid(int, int /*<<< orphan*/, int *);
int check_4th_gen_intel_core_features() {
  uint32_t abcd[4];
  uint32_t fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
  uint32_t avx2_bmi12_mask = (1 << 5) | (1 << 3) | (1 << 8);
  run_cpuid(1, 0, abcd);
  if ((abcd[2] & fma_movbe_osxsave_mask) != fma_movbe_osxsave_mask)
    return 0;
  if (!check_xcr0_ymm())
    return 0;
  run_cpuid(7, 0, abcd);
  if ((abcd[1] & avx2_bmi12_mask) != avx2_bmi12_mask)
    return 0;
  run_cpuid(0x80000001, 0, abcd);
  if ((abcd[2] & (1 << 5)) == 0)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<check_4th_gen_intel_core_features>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x8401000,-0x24(%rbp)
movl   $0x128,-0x28(%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     1161 <check_4th_gen_intel_core_features+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11da <check_4th_gen_intel_core_features+0xba>
mov    $0x0,%al
call   1040 <check_xcr0_ymm@plt>
cmp    $0x0,%eax
jne    117d <check_4th_gen_intel_core_features+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    11da <check_4th_gen_intel_core_features+0xba>
lea    -0x20(%rbp),%rdx
mov    $0x7,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    -0x1c(%rbp),%eax
and    -0x28(%rbp),%eax
cmp    -0x28(%rbp),%eax
je     11a8 <check_4th_gen_intel_core_features+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11da <check_4th_gen_intel_core_features+0xba>
lea    -0x20(%rbp),%rdx
mov    $0x80000001,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    -0x18(%rbp),%eax
and    $0x20,%eax
cmp    $0x0,%eax
jne    11d3 <check_4th_gen_intel_core_features+0xb3>
movl   $0x0,-0x4(%rbp)
jmp    11da <check_4th_gen_intel_core_features+0xba>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_4th_gen_intel_core_features>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
mov    %rsp,%rdx
mov    $0x1,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    0x8(%rsp),%eax
not    %eax
test   $0x8401000,%eax
jne    1187 <check_4th_gen_intel_core_features+0x67>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <check_xcr0_ymm@plt>
test   %eax,%eax
je     1187 <check_4th_gen_intel_core_features+0x67>
xor    %ebx,%ebx
mov    %rsp,%rdx
mov    $0x7,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    0x4(%rsp),%eax
not    %eax
test   $0x128,%eax
jne    1187 <check_4th_gen_intel_core_features+0x67>
mov    %rsp,%rdx
mov    $0x80000001,%edi
xor    %esi,%esi
call   1030 <run_cpuid@plt>
mov    0x8(%rsp),%ebx
shr    $0x5,%ebx
and    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @check_4th_gen_intel_core_features() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 138416128, i32* %3
store i32 296, i32* %4
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%6 = call i32 @run_cpuid(i32 1, i32 0, i32* %5)
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%8 = load i32, i32* %7
%9 = load i32, i32* %3
%10 = and i32 %8, %9
%11 = load i32, i32* %3
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %0
store i32 0, i32* %1
br label %37
14: ; preds = %0
%15 = call i32 (...) @check_xcr0_ymm()
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %14
store i32 0, i32* %1
br label %37
18: ; preds = %14
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%20 = call i32 @run_cpuid(i32 7, i32 0, i32* %19)
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = load i32, i32* %4
%24 = and i32 %22, %23
%25 = load i32, i32* %4
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %18
store i32 0, i32* %1
br label %37
28: ; preds = %18
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%30 = call i32 @run_cpuid(i32 -2147483647, i32 0, i32* %29)
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%32 = load i32, i32* %31
%33 = and i32 %32, 32
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 0, i32* %1
br label %37
36: ; preds = %28
store i32 1, i32* %1
br label %37
37: ; preds = %36, %35, %27, %17, %13
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
define i32 @check_4th_gen_intel_core_features() {
%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, 138416128
%8 = icmp eq i32 %7, 138416128
br i1 %8, label %9, label %23
9: ; preds = %0
%10 = call i32 (...) @check_xcr0_ymm()
%11 = icmp eq i32 %10, 0
br i1 %11, label %23, 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, 296
%17 = icmp eq i32 %16, 296
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = call i32 @run_cpuid(i32 -2147483647, i32 0, i32* %3)
%20 = load i32, i32* %5
%21 = lshr i32 %20, 5
%22 = and i32 %21, 1
br label %23
23: ; preds = %18, %12, %9, %0
%24 = phi i32 [ 0, %0 ], [ 0, %9 ], [ 0, %12 ], [ %22, %18 ]
ret i32 %24
}