void get_cpuid(char buffer[13]) {
  memset(buffer, 0, 1024);
  int eax = 0;
  int ebx, ecx, edx;
  asm volatile("cpuid"
               : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
               : "0"(eax), "2"(ecx));
  ((int *)buffer)[0] = ebx;
  ((int *)buffer)[1] = edx;
  ((int *)buffer)[2] = ecx;
  buffer[12] = 0;
}


x86 assembly (clang, -O0):
<get_cpuid>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
cpuid
mov    %eax,-0x14(%rbp)
mov    %ebx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0xc(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpuid>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x400,%edx
xor    %esi,%esi
call   1030 <memset@plt>
xor    %eax,%eax
cpuid
mov    %ebx,(%r14)
mov    %edx,0x4(%r14)
mov    %ecx,0x8(%r14)
movb   $0x0,0xc(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @get_cpuid(i8* nocapture writeonly %0) {
tail call void @llvm.memset.p0i8.i64(i8* align 1 dereferenceable(1024) %0, i8 0, i64 1024, i1 false)
%2 = tail call { i32, i32, i32, i32 } asm sideeffect "cpuid", "={ax},={bx},={cx},={dx},0,2,~{dirflag},~{fpsr},~{flags}"(i32 0, i32 undef)
%3 = extractvalue { i32, i32, i32, i32 } %2, 1
%4 = extractvalue { i32, i32, i32, i32 } %2, 2
%5 = extractvalue { i32, i32, i32, i32 } %2, 3
%6 = bitcast i8* %0 to i32*
store i32 %3, i32* %6
%7 = getelementptr inbounds i8, i8* %0, i64 4
%8 = bitcast i8* %7 to i32*
store i32 %5, i32* %8
%9 = getelementptr inbounds i8, i8* %0, i64 8
%10 = bitcast i8* %9 to i32*
store i32 %4, i32* %10
%11 = getelementptr inbounds i8, i8* %0, i64 12
store i8 0, i8* %11
ret void
}