#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ cpu_info;

/* Variables and functions */
int /*<<< orphan*/ cpuid(int, int *);
int /*<<< orphan*/ memcpy(char *, int *, int);
void cpu_brand_string(char *s) {
  int cpu_info[4] = {0};
  cpuid((0), cpu_info);
  if (cpu_info[(0)] >= 4) {
    for (int i = 0; i < 4; i++) {
      cpuid(0x80000002 + i, cpu_info);
      memcpy(s, cpu_info, sizeof(cpu_info));
      s += 16;
    }
  }
}


x86 assembly (clang, -O0):
<cpu_brand_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
lea    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <cpuid@plt>
cmpl   $0x4,-0x20(%rbp)
jl     11b5 <cpu_brand_string+0x85>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11b0 <cpu_brand_string+0x80>
mov    -0x24(%rbp),%edi
add    $0x80000002,%edi
lea    -0x20(%rbp),%rsi
call   1050 <cpuid@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <cpu_brand_string+0x38>
jmp    11b5 <cpu_brand_string+0x85>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_brand_string>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <cpuid@plt>
cmpl   $0x4,(%rsp)
jl     11ca <cpu_brand_string+0xaa>
mov    %rsp,%r14
mov    $0x80000002,%edi
mov    %r14,%rsi
call   1040 <cpuid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
lea    0x10(%rbx),%r15
mov    $0x80000003,%edi
mov    %r14,%rsi
call   1040 <cpuid@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
lea    0x20(%rbx),%r15
mov    $0x80000004,%edi
mov    %r14,%rsi
call   1040 <cpuid@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
add    $0x30,%rbx
mov    $0x80000005,%edi
mov    %r14,%rsi
call   1040 <cpuid@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1030 <memcpy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @cpu_brand_string(i8* %0) {
%2 = alloca i8*
%3 = alloca [4 x i32]
%4 = alloca i32
store i8* %0, i8** %2
%5 = bitcast [4 x i32]* %3 to i8*
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%7 = call i32 @cpuid(i32 0, i32* %6)
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%9 = load i32, i32* %8
%10 = icmp sge i32 %9, 4
br i1 %10, label %11, label %29
11: ; preds = %1
store i32 0, i32* %4
br label %12
12: ; preds = %25, %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %28
15: ; preds = %12
%16 = load i32, i32* %4
%17 = add i32 -2147483646, %16
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%19 = call i32 @cpuid(i32 %17, i32* %18)
%20 = load i8*, i8** %2
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%22 = call i32 @memcpy(i8* %20, i32* %21, i32 16)
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 16
store i8* %24, i8** %2
br label %25
25: ; preds = %15
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %12
28: ; preds = %12
br label %29
29: ; preds = %28, %1
ret void
}

LLVM IR (-O2):
define void @cpu_brand_string(i8* %0) {
%2 = alloca [4 x i32]
%3 = bitcast [4 x i32]* %2 to i8*
%4 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%5 = call i32 @cpuid(i32 0, i32* %4)
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 3
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = call i32 @cpuid(i32 -2147483646, i32* %4)
%10 = call i32 @memcpy(i8* %0, i32* %4, i32 16)
%11 = getelementptr inbounds i8, i8* %0, i64 16
%12 = call i32 @cpuid(i32 -2147483645, i32* %4)
%13 = call i32 @memcpy(i8* %11, i32* %4, i32 16)
%14 = getelementptr inbounds i8, i8* %0, i64 32
%15 = call i32 @cpuid(i32 -2147483644, i32* %4)
%16 = call i32 @memcpy(i8* %14, i32* %4, i32 16)
%17 = getelementptr inbounds i8, i8* %0, i64 48
%18 = call i32 @cpuid(i32 -2147483643, i32* %4)
%19 = call i32 @memcpy(i8* %17, i32* %4, i32 16)
br label %20
20: ; preds = %8, %1
ret void
}