void cpuid(long eax_in, long ecx_in, long *eax, long *ebx, long *ecx,
           long *edx) {
  assert(eax);
  assert(ebx);
  assert(ecx);
  assert(edx);
  asm volatile("cpuid"
               : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
               : "a"(eax_in), "c"(ecx_in));
}


x86 assembly (clang, -O0):
<cpuid>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x48,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x38(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cpuid
mov    %rax,%r9
mov    -0x48(%rbp),%rax
mov    %rcx,%rsi
mov    -0x40(%rbp),%rcx
mov    %r9,(%r8)
mov    %rbx,(%rdi)
mov    %rsi,(%rcx)
mov    %rdx,(%rax)
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpuid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rdx,%rdi
xor    %eax,%eax
call   1030 <assert@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <assert@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <assert@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <assert@plt>
mov    %rbp,%rax
mov    %rbx,%rcx
cpuid
mov    %rax,0x0(%r13)
mov    %rbx,(%r12)
mov    %rcx,(%r15)
mov    %rdx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cpuid(i64 %0, i64 %1, i64* %2, i64* %3, i64* %4, i64* %5) {
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i64*
%12 = alloca i64*
store i64 %0, i64* %7
store i64 %1, i64* %8
store i64* %2, i64** %9
store i64* %3, i64** %10
store i64* %4, i64** %11
store i64* %5, i64** %12
%13 = load i64*, i64** %9
%14 = call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %13)
%15 = load i64*, i64** %10
%16 = call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %15)
%17 = load i64*, i64** %11
%18 = call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %17)
%19 = load i64*, i64** %12
%20 = call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %19)
%21 = load i64*, i64** %9
%22 = load i64*, i64** %10
%23 = load i64*, i64** %11
%24 = load i64*, i64** %12
%25 = load i64, i64* %7
%26 = load i64, i64* %8
%27 = call { i64, i64, i64, i64 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},{ax},{cx},~{dirflag},~{fpsr},~{flags}"(i64 %25, i64 %26)
%28 = extractvalue { i64, i64, i64, i64 } %27, 0
%29 = extractvalue { i64, i64, i64, i64 } %27, 1
%30 = extractvalue { i64, i64, i64, i64 } %27, 2
%31 = extractvalue { i64, i64, i64, i64 } %27, 3
store i64 %28, i64* %21
store i64 %29, i64* %22
store i64 %30, i64* %23
store i64 %31, i64* %24
ret void
}

LLVM IR (-O2):
define void @cpuid(i64 %0, i64 %1, i64* %2, i64* %3, i64* %4, i64* %5) {
%7 = tail call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %2)
%8 = tail call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %3)
%9 = tail call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %4)
%10 = tail call i32 (i64*, ...) bitcast (i32 (...)* @assert to i32 (i64*, ...)*)(i64* %5)
%11 = tail call { i64, i64, i64, i64 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},{ax},{cx},~{dirflag},~{fpsr},~{flags}"(i64 %0, i64 %1)
%12 = extractvalue { i64, i64, i64, i64 } %11, 0
%13 = extractvalue { i64, i64, i64, i64 } %11, 1
%14 = extractvalue { i64, i64, i64, i64 } %11, 2
%15 = extractvalue { i64, i64, i64, i64 } %11, 3
store i64 %12, i64* %2
store i64 %13, i64* %3
store i64 %14, i64* %4
store i64 %15, i64* %5
ret void
}