int main(int argc, char **argv) {
  unsigned int eax;
  unsigned int ebx;
  unsigned int ecx;
  unsigned int edx;
  eax = 0x01;
  __asm__ __volatile__("cpuid;"
                       : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
                       : "a"(eax));
  printf("The value of the ecx register is %08x.\n", ecx);
  if (ecx & (1 << 30)) {
    printf("use rdrand\n");
  } else {
    printf("use mt19937");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x28,%rsp
movl   $0x0,-0xc(%rbp)
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cpuid
mov    %eax,-0x1c(%rbp)
mov    %ebx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %edx,-0x28(%rbp)
mov    -0x24(%rbp),%esi
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
je     1174 <main+0x64>
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1182 <main+0x72>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1,%eax
cpuid
mov    %ecx,%ebx
lea    0xecf(%rip),%rdi
mov    %ecx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x40000000,%ebx
jne    1152 <main+0x32>
lea    0xedf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    115e <main+0x3e>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"The value of the ecx register is %08x.\0A\00"
@.str.1 = [12 x i8] c"use rdrand\0A\00"
@.str.2 = [12 x i8] c"use mt19937\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
%10 = load i32, i32* %6
%11 = call { i32, i32, i32, i32 } asm sideeffect "cpuid;", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 %10)
%12 = extractvalue { i32, i32, i32, i32 } %11, 0
%13 = extractvalue { i32, i32, i32, i32 } %11, 1
%14 = extractvalue { i32, i32, i32, i32 } %11, 2
%15 = extractvalue { i32, i32, i32, i32 } %11, 3
store i32 %12, i32* %6
store i32 %13, i32* %7
store i32 %14, i32* %8
store i32 %15, i32* %9
%16 = load i32, i32* %8
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %8
%19 = and i32 %18, 1073741824
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"The value of the ecx register is %08x.\0A\00"
@.str.2 = [12 x i8] c"use mt19937\00"
@str = [11 x i8] c"use rdrand\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call { i32, i32, i32, i32 } asm sideeffect "cpuid;", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 1)
%4 = extractvalue { i32, i32, i32, i32 } %3, 2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = and i32 %4, 1073741824
%7 = icmp eq i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
ret i32 0
}