#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(unsigned int, int, unsigned int *);
int is_cpu_feature_present(unsigned func, unsigned reg, unsigned bit) {
  unsigned cpuinfo[4] = {0};
  cpuid(0x0, 0x0, cpuinfo);
  if (cpuinfo[0] < func)
    return 0;
  cpuid(func, 0x0, cpuinfo);
  return (cpuinfo[reg] & bit) != 0;
}


x86 assembly (clang, -O0):
<is_cpu_feature_present>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x20(%rbp),%rdx
xor    %esi,%esi
mov    %esi,%edi
call   1040 <cpuid@plt>
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1166 <is_cpu_feature_present+0x46>
movl   $0x0,-0x4(%rbp)
jmp    118c <is_cpu_feature_present+0x6c>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <cpuid@plt>
mov    -0xc(%rbp),%eax
mov    -0x20(%rbp,%rax,4),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_cpu_feature_present>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
xor    %ebp,%ebp
mov    %rsp,%rdx
xor    %edi,%edi
xor    %esi,%esi
call   1030 <cpuid@plt>
cmp    %ebx,(%rsp)
jb     1155 <is_cpu_feature_present+0x45>
mov    %rsp,%rdx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <cpuid@plt>
mov    %r15d,%eax
xor    %ebp,%ebp
test   %r14d,(%rsp,%rax,4)
setne  %bpl
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_cpu_feature_present(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4 x i32]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = bitcast [4 x i32]* %8 to i8*
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%11 = call i32 @cpuid(i32 0, i32 0, i32* %10)
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%13 = load i32, i32* %12
%14 = load i32, i32* %5
%15 = icmp ult i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %29
17: ; preds = %3
%18 = load i32, i32* %5
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 0
%20 = call i32 @cpuid(i32 %18, i32 0, i32* %19)
%21 = load i32, i32* %6
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %8, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = load i32, i32* %7
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
store i32 %28, i32* %4
br label %29
29: ; preds = %17, %16
%30 = load i32, i32* %4
ret i32 %30
}

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