#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 */

/* Variables and functions */
int /*<<< orphan*/ __cpuid(int, unsigned int, unsigned int, unsigned int,
                           unsigned int);
int asprintf(char **, char *, char *, unsigned int, unsigned int, ...);
char *get_cpu_str_type(char *type, char **idstr_step) {
  char *res;
  union {
    struct {
      unsigned b, c, d;
    } f;
    char str[13];
  } vendor;
  unsigned a, b, c, d;
  unsigned stepping, family, model;
  int n;
  vendor.str[12] = 0;
  __cpuid(0, a, vendor.f.b, vendor.f.d, vendor.f.c);
  __cpuid(1, a, b, c, d);
  stepping = a & 0xf;
  model = (a >> 4) & 0xf;
  family = (a >> 8) & 0xf;
  if (family == 0xf)
    family += (a >> 20) & 0xff;
  if (family == 6 || family == 0xf)
    model += ((a >> 16) & 0xf) << 4;
  if (idstr_step)
    asprintf(idstr_step, "%s-%d-%X-%X%s", vendor.str, family, model, stepping,
             type);
  n = asprintf(&res, "%s-%d-%X%s", vendor.str, family, model, type);
  if (n < 0)
    res = NULL;
  return res;
}


x86 assembly (clang, -O0):
<get_cpu_str_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
xor    %edi,%edi
call   1030 <__cpuid@plt>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
mov    -0x38(%rbp),%r8d
mov    $0x1,%edi
call   1030 <__cpuid@plt>
mov    -0x2c(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%eax
shr    $0x4,%eax
and    $0xf,%eax
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%eax
shr    $0x8,%eax
and    $0xf,%eax
mov    %eax,-0x40(%rbp)
cmpl   $0xf,-0x40(%rbp)
jne    119b <get_cpu_str_type+0x7b>
mov    -0x2c(%rbp),%eax
shr    $0x14,%eax
and    $0xff,%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
cmpl   $0x6,-0x40(%rbp)
je     11af <get_cpu_str_type+0x8f>
cmpl   $0xf,-0x40(%rbp)
jne    11c1 <get_cpu_str_type+0xa1>
mov    -0x2c(%rbp),%eax
shr    $0x10,%eax
and    $0xf,%eax
shl    $0x4,%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f5 <get_cpu_str_type+0xd5>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%ecx
mov    -0x44(%rbp),%r8d
mov    -0x3c(%rbp),%r9d
mov    -0x8(%rbp),%rax
lea    0xe16(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <asprintf@plt>
lea    -0x28(%rbp),%rdx
mov    -0x40(%rbp),%ecx
mov    -0x44(%rbp),%r8d
mov    -0x8(%rbp),%r9
lea    -0x18(%rbp),%rdi
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1040 <asprintf@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    122b <get_cpu_str_type+0x10b>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_str_type>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,0x24(%rsp)
xor    %edi,%edi
call   1030 <__cpuid@plt>
mov    $0x1,%edi
call   1030 <__cpuid@plt>
test   %rbx,%rbx
je     116a <get_cpu_str_type+0x4a>
mov    %r14,(%rsp)
lea    0xead(%rip),%rsi
lea    0x18(%rsp),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
xor    %eax,%eax
call   1040 <asprintf@plt>
lea    0xe9d(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%rdi
lea    0x18(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
xor    %eax,%eax
call   1040 <asprintf@plt>
test   %eax,%eax
js     1195 <get_cpu_str_type+0x75>
mov    0x10(%rsp),%rbx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.anon = type { %struct.anon, [4 x i8] }
%struct.anon = type { i32, i32, i32 }
@.str = [14 x i8] c"%s-%d-%X-%X%s\00"
@.str.1 = [11 x i8] c"%s-%d-%X%s\00"
define i8* @get_cpu_str_type(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca %union.anon
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%15 = bitcast %union.anon* %6 to [13 x i8]*
%16 = getelementptr inbounds [13 x i8], [13 x i8]* %15, i64 0, i64 12
store i8 0, i8* %16
%17 = load i32, i32* %7
%18 = bitcast %union.anon* %6 to %struct.anon*
%19 = getelementptr inbounds %struct.anon, %struct.anon* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = bitcast %union.anon* %6 to %struct.anon*
%22 = getelementptr inbounds %struct.anon, %struct.anon* %21, i32 0, i32 2
%23 = load i32, i32* %22
%24 = bitcast %union.anon* %6 to %struct.anon*
%25 = getelementptr inbounds %struct.anon, %struct.anon* %24, i32 0, i32 1
%26 = load i32, i32* %25
%27 = call i32 @__cpuid(i32 0, i32 %17, i32 %20, i32 %23, i32 %26)
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i32 @__cpuid(i32 1, i32 %28, i32 %29, i32 %30, i32 %31)
%33 = load i32, i32* %7
%34 = and i32 %33, 15
store i32 %34, i32* %11
%35 = load i32, i32* %7
%36 = lshr i32 %35, 4
%37 = and i32 %36, 15
store i32 %37, i32* %13
%38 = load i32, i32* %7
%39 = lshr i32 %38, 8
%40 = and i32 %39, 15
store i32 %40, i32* %12
%41 = load i32, i32* %12
%42 = icmp eq i32 %41, 15
br i1 %42, label %43, label %49
43: ; preds = %2
%44 = load i32, i32* %7
%45 = lshr i32 %44, 20
%46 = and i32 %45, 255
%47 = load i32, i32* %12
%48 = add i32 %47, %46
store i32 %48, i32* %12
br label %49
49: ; preds = %43, %2
%50 = load i32, i32* %12
%51 = icmp eq i32 %50, 6
br i1 %51, label %55, label %52
52: ; preds = %49
%53 = load i32, i32* %12
%54 = icmp eq i32 %53, 15
br i1 %54, label %55, label %62
55: ; preds = %52, %49
%56 = load i32, i32* %7
%57 = lshr i32 %56, 16
%58 = and i32 %57, 15
%59 = shl i32 %58, 4
%60 = load i32, i32* %13
%61 = add i32 %60, %59
store i32 %61, i32* %13
br label %62
62: ; preds = %55, %52
%63 = load i8**, i8*** %4
%64 = icmp ne i8** %63, null
br i1 %64, label %65, label %74
65: ; preds = %62
%66 = load i8**, i8*** %4
%67 = bitcast %union.anon* %6 to [13 x i8]*
%68 = getelementptr inbounds [13 x i8], [13 x i8]* %67, i64 0, i64 0
%69 = load i32, i32* %12
%70 = load i32, i32* %13
%71 = load i32, i32* %11
%72 = load i8*, i8** %3
%73 = call i32 (i8**, i8*, i8*, i32, i32, ...) @asprintf(i8** %66, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %68, i32 %69, i32 %70, i32 %71, i8* %72)
br label %74
74: ; preds = %65, %62
%75 = bitcast %union.anon* %6 to [13 x i8]*
%76 = getelementptr inbounds [13 x i8], [13 x i8]* %75, i64 0, i64 0
%77 = load i32, i32* %12
%78 = load i32, i32* %13
%79 = load i8*, i8** %3
%80 = call i32 (i8**, i8*, i8*, i32, i32, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %76, i32 %77, i32 %78, i8* %79)
store i32 %80, i32* %14
%81 = load i32, i32* %14
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %74
store i8* null, i8** %5
br label %84
84: ; preds = %83, %74
%85 = load i8*, i8** %5
ret i8* %85
}

LLVM IR (-O2):
%union.anon = type { %struct.anon, [4 x i8] }
%struct.anon = type { i32, i32, i32 }
@.str = [14 x i8] c"%s-%d-%X-%X%s\00"
@.str.1 = [11 x i8] c"%s-%d-%X%s\00"
define i8* @get_cpu_str_type(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca %union.anon
%5 = bitcast i8** %3 to i8*
%6 = bitcast %union.anon* %4 to i8*
%7 = getelementptr inbounds %union.anon, %union.anon* %4, i64 0, i32 1, i64 0
store i8 0, i8* %7
%8 = tail call i32 @__cpuid(i32 0, i32 undef, i32 undef, i32 undef, i32 undef)
%9 = tail call i32 @__cpuid(i32 1, i32 undef, i32 undef, i32 undef, i32 undef)
%10 = icmp eq i8** %1, null
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 (i8**, i8*, i8*, i32, i32, ...) @asprintf(i8** %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %6, i32 0, i32 0, i32 0, i8* %0)
br label %13
13: ; preds = %11, %2
%14 = call i32 (i8**, i8*, i8*, i32, i32, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %6, i32 0, i32 0, i8* %0)
%15 = icmp slt i32 %14, 0
%16 = load i8*, i8** %3
%17 = select i1 %15, i8* null, i8* %16
ret i8* %17
}