void get_cpuid_signature(int cpuid_file, char *signature) {
  int ebx = 0, ecx = 0, edx = 0, eax = 1;
  __asm__("cpuid" : "=b"(ebx), "=c"(ecx), "=d"(edx), "=a"(eax) : "a"(eax));
  int model = (eax & 0x0FF) >> 4;
  int extended_model = (eax & 0xF0000) >> 12;
  int family_code = (eax & 0xF00) >> 8;
  int extended_family_code = (eax & 0xFF00000) >> 16;
  snprintf(signature, sizeof(signature), "%02x_%x",
           extended_family_code | family_code, extended_model | model);
}


x86 assembly (clang, -O0):
<get_cpuid_signature>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x38,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cpuid
mov    %ebx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
sar    $0x4,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
and    $0xf0000,%eax
sar    $0xc,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
and    $0xf00,%eax
sar    $0x8,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff00000,%eax
sar    $0x10,%eax
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%ecx
or     -0x34(%rbp),%ecx
mov    -0x30(%rbp),%r8d
or     -0x2c(%rbp),%r8d
mov    $0x8,%esi
lea    0xe5d(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpuid_signature>:
push   %rbx
mov    %rsi,%rdi
mov    $0x1,%eax
cpuid
mov    %eax,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
mov    %eax,%r8d
shr    $0xc,%r8d
and    $0xf0,%r8d
or     %ecx,%r8d
mov    %eax,%ecx
shr    $0x8,%ecx
and    $0xf,%ecx
shr    $0x10,%eax
and    $0xff0,%eax
or     %eax,%ecx
lea    0xeb3(%rip),%rdx
mov    $0x8,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%02x_%x\00"
define void @get_cpuid_signature(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
%13 = load i32, i32* %8
%14 = call { i32, i32, i32, i32 } asm "cpuid", "={bx},={cx},={dx},={ax},{ax},~{dirflag},~{fpsr},~{flags}"(i32 %13)
%15 = extractvalue { i32, i32, i32, i32 } %14, 0
%16 = extractvalue { i32, i32, i32, i32 } %14, 1
%17 = extractvalue { i32, i32, i32, i32 } %14, 2
%18 = extractvalue { i32, i32, i32, i32 } %14, 3
store i32 %15, i32* %5
store i32 %16, i32* %6
store i32 %17, i32* %7
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = and i32 %19, 255
%21 = ashr i32 %20, 4
store i32 %21, i32* %9
%22 = load i32, i32* %8
%23 = and i32 %22, 983040
%24 = ashr i32 %23, 12
store i32 %24, i32* %10
%25 = load i32, i32* %8
%26 = and i32 %25, 3840
%27 = ashr i32 %26, 8
store i32 %27, i32* %11
%28 = load i32, i32* %8
%29 = and i32 %28, 267386880
%30 = ashr i32 %29, 16
store i32 %30, i32* %12
%31 = load i8*, i8** %4
%32 = load i32, i32* %12
%33 = load i32, i32* %11
%34 = or i32 %32, %33
%35 = load i32, i32* %10
%36 = load i32, i32* %9
%37 = or i32 %35, %36
%38 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %31, i64 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %37)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%02x_%x\00"
define void @get_cpuid_signature(i32 %0, i8* nocapture writeonly %1) {
%3 = tail call { i32, i32, i32, i32 } asm "cpuid", "={bx},={cx},={dx},={ax},{ax},~{dirflag},~{fpsr},~{flags}"(i32 1)
%4 = extractvalue { i32, i32, i32, i32 } %3, 3
%5 = lshr i32 %4, 4
%6 = and i32 %5, 15
%7 = lshr i32 %4, 12
%8 = and i32 %7, 240
%9 = lshr i32 %4, 8
%10 = and i32 %9, 15
%11 = lshr i32 %4, 16
%12 = and i32 %11, 4080
%13 = or i32 %12, %10
%14 = or i32 %8, %6
%15 = tail call i32 (i8*, i64, i8*, ...) @snprintf(i8* dereferenceable(1) %1, i64 8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
ret void
}