int RdRand_cpuid() {
  int info[4] = {-1, -1, -1, -1};
  asm volatile("cpuid"
               : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3])
               : "a"(0));
  if (memcmp((void *)&info[1], (void *)"Genu", 4) != 0 ||
      memcmp((void *)&info[3], (void *)"ineI", 4) != 0 ||
      memcmp((void *)&info[2], (void *)"ntel", 4) != 0) {
    return 0;
  }
  asm volatile("cpuid"
               : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3])
               : "a"(1));
  int ecx = info[2];
  if ((ecx & 0x40000000) == 0x40000000)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<RdRand_cpuid>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
mov    0xef4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xef1(%rip),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cpuid
mov    %eax,-0x20(%rbp)
mov    %ebx,-0x1c(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x20(%rbp),%rax
add    $0x4,%rax
mov    (%rax),%eax
sub    $0x756e6547,%eax
setne  %al
movzbl %al,%eax
cmp    $0x0,%eax
jne    1185 <RdRand_cpuid+0x85>
lea    -0x20(%rbp),%rax
add    $0xc,%rax
mov    (%rax),%eax
sub    $0x49656e69,%eax
setne  %al
movzbl %al,%eax
cmp    $0x0,%eax
jne    1185 <RdRand_cpuid+0x85>
lea    -0x20(%rbp),%rax
add    $0x8,%rax
mov    (%rax),%eax
sub    $0x6c65746e,%eax
setne  %al
movzbl %al,%eax
cmp    $0x0,%eax
je     1191 <RdRand_cpuid+0x91>
movl   $0x0,-0xc(%rbp)
jmp    11d0 <RdRand_cpuid+0xd0>
mov    $0x1,%eax
cpuid
mov    %eax,-0x20(%rbp)
mov    %ebx,-0x1c(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
and    $0x40000000,%eax
cmp    $0x40000000,%eax
jne    11c9 <RdRand_cpuid+0xc9>
movl   $0x1,-0xc(%rbp)
jmp    11d0 <RdRand_cpuid+0xd0>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<RdRand_cpuid>:
push   %rbx
xor    %esi,%esi
xor    %eax,%eax
cpuid
cmp    $0x756e6547,%ebx
jne    112e <RdRand_cpuid+0x2e>
cmp    $0x49656e69,%edx
jne    112e <RdRand_cpuid+0x2e>
cmp    $0x6c65746e,%ecx
jne    112e <RdRand_cpuid+0x2e>
mov    $0x1,%eax
cpuid
mov    %ecx,%esi
shr    $0x1e,%esi
and    $0x1,%esi
mov    %esi,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.RdRand_cpuid.info = [4 x i32] [i32 -1, i32 -1, i32 -1, i32 -1]
@.str = [5 x i8] c"Genu\00"
@.str.1 = [5 x i8] c"ineI\00"
@.str.2 = [5 x i8] c"ntel\00"
define i32 @RdRand_cpuid() {
%1 = alloca i32
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = bitcast [4 x i32]* %2 to i8*
%5 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%9 = call { i32, i32, i32, i32 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 0)
%10 = extractvalue { i32, i32, i32, i32 } %9, 0
%11 = extractvalue { i32, i32, i32, i32 } %9, 1
%12 = extractvalue { i32, i32, i32, i32 } %9, 2
%13 = extractvalue { i32, i32, i32, i32 } %9, 3
store i32 %10, i32* %5
store i32 %11, i32* %6
store i32 %12, i32* %7
store i32 %13, i32* %8
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%15 = bitcast i32* %14 to i8*
%16 = call i32 @memcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4)
%17 = icmp ne i32 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %0
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%20 = bitcast i32* %19 to i8*
%21 = call i32 @memcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%25 = bitcast i32* %24 to i8*
%26 = call i32 @memcmp(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23, %18, %0
store i32 0, i32* %1
br label %46
29: ; preds = %23
%30 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%32 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%34 = call { i32, i32, i32, i32 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 1)
%35 = extractvalue { i32, i32, i32, i32 } %34, 0
%36 = extractvalue { i32, i32, i32, i32 } %34, 1
%37 = extractvalue { i32, i32, i32, i32 } %34, 2
%38 = extractvalue { i32, i32, i32, i32 } %34, 3
store i32 %35, i32* %30
store i32 %36, i32* %31
store i32 %37, i32* %32
store i32 %38, i32* %33
%39 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%40 = load i32, i32* %39
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = and i32 %41, 1073741824
%43 = icmp eq i32 %42, 1073741824
br i1 %43, label %44, label %45
44: ; preds = %29
store i32 1, i32* %1
br label %46
45: ; preds = %29
store i32 0, i32* %1
br label %46
46: ; preds = %45, %44, %28
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
define i32 @RdRand_cpuid() {
%1 = tail call { i32, i32, i32, i32 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 0)
%2 = extractvalue { i32, i32, i32, i32 } %1, 1
%3 = extractvalue { i32, i32, i32, i32 } %1, 2
%4 = extractvalue { i32, i32, i32, i32 } %1, 3
%5 = icmp eq i32 %2, 1970169159
%6 = icmp eq i32 %4, 1231384169
%7 = select i1 %5, i1 %6, i1 false
%8 = icmp eq i32 %3, 1818588270
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = tail call { i32, i32, i32, i32 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 1)
%12 = extractvalue { i32, i32, i32, i32 } %11, 2
%13 = lshr i32 %12, 30
%14 = and i32 %13, 1
br label %15
15: ; preds = %0, %10
%16 = phi i32 [ %14, %10 ], [ 0, %0 ]
ret i32 %16
}