#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*/ __get_cpuid(unsigned int, unsigned int *, unsigned int *,
                               unsigned int *, unsigned int *);
int supports_bmi2() {
  static int supports_bmi2_cache = -1;
  if (supports_bmi2_cache != -1) {
    return supports_bmi2_cache;
  }
  unsigned int level = 0;
  unsigned int eax = 1;
  unsigned int ebx, ecx, edx;
  __get_cpuid(level, &eax, &ebx, &ecx, &edx);
  supports_bmi2_cache = (ebx >> 8) & 1;
  return supports_bmi2_cache;
}


x86 assembly (clang, -O0):
<supports_bmi2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0xffffffff,0x2f09(%rip)
je     1133 <supports_bmi2+0x23>
mov    0x2efd(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    1171 <supports_bmi2+0x61>
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1030 <__get_cpuid@plt>
mov    -0x10(%rbp),%eax
shr    $0x8,%eax
and    $0x1,%eax
mov    %eax,0x2ec0(%rip)
mov    0x2eba(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<supports_bmi2>:
sub    $0x18,%rsp
mov    0x2f0e(%rip),%eax
cmp    $0xffffffff,%eax
je     1124 <supports_bmi2+0x14>
add    $0x18,%rsp
ret
movl   $0x1,0xc(%rsp)
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
xor    %edi,%edi
call   1030 <__get_cpuid@plt>
mov    0x8(%rsp),%eax
shr    $0x8,%eax
and    $0x1,%eax
mov    %eax,0x2ed1(%rip)
add    $0x18,%rsp
ret

LLVM IR (-O0):
@supports_bmi2.supports_bmi2_cache = internal global i32 -1
define i32 @supports_bmi2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i32, i32* @supports_bmi2.supports_bmi2_cache
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = load i32, i32* @supports_bmi2.supports_bmi2_cache
store i32 %10, i32* %1
br label %18
11: ; preds = %0
store i32 0, i32* %2
store i32 1, i32* %3
%12 = load i32, i32* %2
%13 = call i32 @__get_cpuid(i32 %12, i32* %3, i32* %4, i32* %5, i32* %6)
%14 = load i32, i32* %4
%15 = lshr i32 %14, 8
%16 = and i32 %15, 1
store i32 %16, i32* @supports_bmi2.supports_bmi2_cache
%17 = load i32, i32* @supports_bmi2.supports_bmi2_cache
store i32 %17, i32* %1
br label %18
18: ; preds = %11, %9
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@supports_bmi2.supports_bmi2_cache = internal unnamed_addr global i32 -1
define i32 @supports_bmi2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @supports_bmi2.supports_bmi2_cache
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = bitcast i32* %1 to i8*
store i32 1, i32* %1
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = call i32 @__get_cpuid(i32 0, i32* %1, i32* %2, i32* %3, i32* %4)
%13 = load i32, i32* %2
%14 = lshr i32 %13, 8
%15 = and i32 %14, 1
store i32 %15, i32* @supports_bmi2.supports_bmi2_cache
br label %16
16: ; preds = %0, %7
%17 = phi i32 [ %15, %7 ], [ %5, %0 ]
ret i32 %17
}