void dump_kvm_leafs(unsigned base) {
  unsigned int eax, ebx, ecx, edx;
  asm("cpuid"
      : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
      : "a"(0x40000000 | base));
  if ((ebx == 0x4b4d564b) && (ecx == 0x564b4d56) && (edx == 0x4d)) {
    print_leaf(base | 0x40000000, 0);
    print_leaf(base | 0x40000001, 0);
  } else if (base == 0x40000000 && (ebx == 0x7263694d) && (ecx == 0x666f736f) &&
             (edx == 0x76482074)) {
    print_leaf(0x40000000, 0);
    print_leaf(0x40000001, 0);
    print_leaf(0x40000002, 0);
    print_leaf(0x40000003, 0);
    print_leaf(0x40000004, 0);
    print_leaf(0x40000005, 0);
  }
}


x86 assembly (clang, -O0):
<dump_kvm_leafs>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x40000000,%eax
cpuid
mov    %eax,-0x10(%rbp)
mov    %ebx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0x4b4d564b,-0x14(%rbp)
jne    117f <dump_kvm_leafs+0x6f>
cmpl   $0x564b4d56,-0x18(%rbp)
jne    117f <dump_kvm_leafs+0x6f>
cmpl   $0x4d,-0x1c(%rbp)
jne    117f <dump_kvm_leafs+0x6f>
mov    -0xc(%rbp),%edi
or     $0x40000000,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
mov    -0xc(%rbp),%edi
or     $0x40000001,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
jmp    120c <dump_kvm_leafs+0xfc>
cmpl   $0x40000000,-0xc(%rbp)
jne    1207 <dump_kvm_leafs+0xf7>
cmpl   $0x7263694d,-0x14(%rbp)
jne    1207 <dump_kvm_leafs+0xf7>
cmpl   $0x666f736f,-0x18(%rbp)
jne    1207 <dump_kvm_leafs+0xf7>
cmpl   $0x76482074,-0x1c(%rbp)
jne    1207 <dump_kvm_leafs+0xf7>
mov    $0x40000000,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
mov    $0x40000001,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
mov    $0x40000002,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
mov    $0x40000003,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
mov    $0x40000004,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
mov    $0x40000005,%edi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <print_leaf@plt>
jmp    120c <dump_kvm_leafs+0xfc>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_kvm_leafs>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
or     $0x40000000,%edi
mov    %edi,%eax
cpuid
cmp    $0x4b4d564b,%ebx
jne    1145 <dump_kvm_leafs+0x35>
cmp    $0x564b4d56,%ecx
jne    1145 <dump_kvm_leafs+0x35>
cmp    $0x4d,%edx
jne    1145 <dump_kvm_leafs+0x35>
xor    %esi,%esi
xor    %eax,%eax
call   1030 <print_leaf@plt>
or     $0x40000001,%ebp
jmp    11b0 <dump_kvm_leafs+0xa0>
cmp    $0x40000000,%ebp
jne    11c1 <dump_kvm_leafs+0xb1>
cmp    $0x7263694d,%ebx
jne    11c1 <dump_kvm_leafs+0xb1>
cmp    $0x666f736f,%ecx
jne    11c1 <dump_kvm_leafs+0xb1>
cmp    $0x76482074,%edx
jne    11c1 <dump_kvm_leafs+0xb1>
mov    $0x40000000,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <print_leaf@plt>
mov    $0x40000001,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <print_leaf@plt>
mov    $0x40000002,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <print_leaf@plt>
mov    $0x40000003,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <print_leaf@plt>
mov    $0x40000004,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <print_leaf@plt>
mov    $0x40000005,%ebp
mov    %ebp,%edi
xor    %esi,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <print_leaf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @dump_kvm_leafs(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = or i32 1073741824, %7
%9 = call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 %8)
%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* %3
store i32 %11, i32* %4
store i32 %12, i32* %5
store i32 %13, i32* %6
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 1263359563
br i1 %15, label %16, label %29
16: ; preds = %1
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 1447775574
br i1 %18, label %19, label %29
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 77
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %2
%24 = or i32 %23, 1073741824
%25 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 %24, i32 0)
%26 = load i32, i32* %2
%27 = or i32 %26, 1073741825
%28 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 %27, i32 0)
br label %49
29: ; preds = %19, %16, %1
%30 = load i32, i32* %2
%31 = icmp eq i32 %30, 1073741824
br i1 %31, label %32, label %48
32: ; preds = %29
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 1919117645
br i1 %34, label %35, label %48
35: ; preds = %32
%36 = load i32, i32* %5
%37 = icmp eq i32 %36, 1718580079
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, 1984438388
br i1 %40, label %41, label %48
41: ; preds = %38
%42 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741824, i32 0)
%43 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741825, i32 0)
%44 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741826, i32 0)
%45 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741827, i32 0)
%46 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741828, i32 0)
%47 = call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741829, i32 0)
br label %48
48: ; preds = %41, %38, %35, %32, %29
br label %49
49: ; preds = %48, %22
ret void
}

LLVM IR (-O2):
define void @dump_kvm_leafs(i32 %0) {
%2 = or i32 %0, 1073741824
%3 = tail call { i32, i32, i32, i32 } asm "cpuid", "={ax},={bx},={cx},={dx},{ax},~{dirflag},~{fpsr},~{flags}"(i32 %2)
%4 = extractvalue { i32, i32, i32, i32 } %3, 1
%5 = extractvalue { i32, i32, i32, i32 } %3, 2
%6 = extractvalue { i32, i32, i32, i32 } %3, 3
%7 = icmp eq i32 %4, 1263359563
%8 = icmp eq i32 %5, 1447775574
%9 = select i1 %7, i1 %8, i1 false
%10 = icmp eq i32 %6, 77
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 %2, i32 0)
%14 = or i32 %0, 1073741825
br label %29
15: ; preds = %1
%16 = icmp eq i32 %0, 1073741824
%17 = icmp eq i32 %4, 1919117645
%18 = select i1 %16, i1 %17, i1 false
%19 = icmp eq i32 %5, 1718580079
%20 = select i1 %18, i1 %19, i1 false
%21 = icmp eq i32 %6, 1984438388
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %32
23: ; preds = %15
%24 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741824, i32 0)
%25 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741825, i32 0)
%26 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741826, i32 0)
%27 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741827, i32 0)
%28 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 1073741828, i32 0)
br label %29
29: ; preds = %12, %23
%30 = phi i32 [ 1073741829, %23 ], [ %14, %12 ]
%31 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @print_leaf to i32 (i32, i32, ...)*)(i32 %30, i32 0)
br label %32
32: ; preds = %29, %15
ret void
}