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

/* Variables and functions */
int asprintf(char **, char *, char *, int, int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int sscanf(char *, char *, ...);
char *get_cpu_str_type(char *type) {
  char *line = NULL;
  size_t llen = 0;
  int found = 0, n;
  char vendor[30];
  int model = 0, fam = 0;
  char *res = NULL;
  FILE *f = fopen("/proc/cpuinfo", "r");
  if (!f)
    return NULL;
  while (getline(&line, &llen, f) > 0) {
    if (sscanf(line, "vendor_id : %29s", vendor) == 1)
      found++;
    else if (sscanf(line, "model : %d", &model) == 1)
      found++;
    else if (sscanf(line, "cpu family : %d", &fam) == 1)
      found++;
    if (found == 3) {
      n = asprintf(&res, "%s-%d-%X%s", vendor, fam, model, type);
      if (n < 0)
        res = NULL;
      break;
    }
  }
  free(line);
  fclose(f);
  return res;
}


x86 assembly (clang, -O0):
<get_cpu_str_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
lea    0xe60(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11c8 <get_cpu_str_type+0x68>
movq   $0x0,-0x8(%rbp)
jmp    12d6 <get_cpu_str_type+0x176>
jmp    11cd <get_cpu_str_type+0x6d>
mov    -0x68(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
cmp    $0x0,%rax
jle    12bc <get_cpu_str_type+0x15c>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1215 <get_cpu_str_type+0xb5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1274 <get_cpu_str_type+0x114>
mov    -0x18(%rbp),%rdi
lea    0xe01(%rip),%rsi
lea    -0x54(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1242 <get_cpu_str_type+0xe2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    126f <get_cpu_str_type+0x10f>
mov    -0x18(%rbp),%rdi
lea    0xddf(%rip),%rsi
lea    -0x58(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    126a <get_cpu_str_type+0x10a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    126f <get_cpu_str_type+0x10f>
jmp    1274 <get_cpu_str_type+0x114>
cmpl   $0x3,-0x24(%rbp)
jne    12b7 <get_cpu_str_type+0x157>
lea    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%ecx
mov    -0x54(%rbp),%r8d
mov    -0x10(%rbp),%r9
lea    -0x60(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   1060 <asprintf@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    12b2 <get_cpu_str_type+0x152>
movq   $0x0,-0x60(%rbp)
jmp    12bc <get_cpu_str_type+0x15c>
jmp    11cd <get_cpu_str_type+0x6d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_str_type>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x28(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe5d(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
test   %rbx,%rbx
je     12ad <get_cpu_str_type+0x14d>
mov    %rbp,0x20(%rsp)
lea    0x8(%rsp),%r15
lea    0x28(%rsp),%r12
lea    0x30(%rsp),%rbp
xor    %r14d,%r14d
jmp    11e9 <get_cpu_str_type+0x89>
cs nopw 0x0(%rax,%rax,1)
add    %r13d,%r14d
cmp    $0x3,%r14d
je     1265 <get_cpu_str_type+0x105>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
test   %rax,%rax
jle    1296 <get_cpu_str_type+0x136>
mov    0x8(%rsp),%rdi
lea    0xe04(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    $0x1,%r13d
cmp    $0x1,%eax
je     11e0 <get_cpu_str_type+0x80>
mov    0x8(%rsp),%rdi
lea    0xdf4(%rip),%rsi
lea    0x14(%rsp),%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11e0 <get_cpu_str_type+0x80>
mov    0x8(%rsp),%rdi
lea    0xde2(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
xor    %r13d,%r13d
cmp    $0x1,%eax
sete   %r13b
jmp    11e0 <get_cpu_str_type+0x80>
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
lea    0xdc7(%rip),%rsi
lea    0x18(%rsp),%rdi
lea    0x30(%rsp),%rdx
mov    0x20(%rsp),%r9
call   1060 <asprintf@plt>
test   %eax,%eax
jns    1296 <get_cpu_str_type+0x136>
movq   $0x0,0x18(%rsp)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x18(%rsp),%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"vendor_id : %29s\00"
@.str.3 = [11 x i8] c"model : %d\00"
@.str.4 = [16 x i8] c"cpu family : %d\00"
@.str.5 = [11 x i8] c"%s-%d-%X%s\00"
define i8* @get_cpu_str_type(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca [30 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32*
store i8* %0, i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i32 0, i32* %6
store i32 0, i32* %9
store i32 0, i32* %10
store i8* null, i8** %11
%13 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %12
%14 = load i32*, i32** %12
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
store i8* null, i8** %2
br label %66
17: ; preds = %1
br label %18
18: ; preds = %59, %17
%19 = load i32*, i32** %12
%20 = call i64 @getline(i8** %4, i64* %5, i32* %19)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %60
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sscanf(i8* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %46
30: ; preds = %22
%31 = load i8*, i8** %4
%32 = call i32 (i8*, i8*, ...) @sscanf(i8* %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %9)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %45
37: ; preds = %30
%38 = load i8*, i8** %4
%39 = call i32 (i8*, i8*, ...) @sscanf(i8* %38, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32* %10)
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %44
44: ; preds = %41, %37
br label %45
45: ; preds = %44, %34
br label %46
46: ; preds = %45, %27
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %59
49: ; preds = %46
%50 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* %10
%52 = load i32, i32* %9
%53 = load i8*, i8** %3
%54 = call i32 @asprintf(i8** %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %50, i32 %51, i32 %52, i8* %53)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %49
store i8* null, i8** %11
br label %58
58: ; preds = %57, %49
br label %60
59: ; preds = %46
br label %18
60: ; preds = %58, %18
%61 = load i8*, i8** %4
%62 = call i32 @free(i8* %61)
%63 = load i32*, i32** %12
%64 = call i32 @fclose(i32* %63)
%65 = load i8*, i8** %11
store i8* %65, i8** %2
br label %66
66: ; preds = %60, %16
%67 = load i8*, i8** %2
ret i8* %67
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"vendor_id : %29s\00"
@.str.3 = [11 x i8] c"model : %d\00"
@.str.4 = [16 x i8] c"cpu family : %d\00"
@.str.5 = [11 x i8] c"%s-%d-%X%s\00"
define i8* @get_cpu_str_type(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca [30 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%9 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %48, label %16
16: ; preds = %1, %33
%17 = phi i32 [ %35, %33 ], [ 0, %1 ]
%18 = call i64 @getline(i8** %2, i64* %3, i32* %14)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %43
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = call i32 (i8*, i8*, ...) @sscanf(i8* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%23 = icmp eq i32 %22, 1
br i1 %23, label %33, label %24
24: ; preds = %20
%25 = load i8*, i8** %2
%26 = call i32 (i8*, i8*, ...) @sscanf(i8* %25, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%27 = icmp eq i32 %26, 1
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i8*, i8** %2
%30 = call i32 (i8*, i8*, ...) @sscanf(i8* %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%31 = icmp eq i32 %30, 1
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %24, %20, %28
%34 = phi i32 [ %32, %28 ], [ 1, %20 ], [ 1, %24 ]
%35 = add nuw nsw i32 %17, %34
%36 = icmp eq i32 %35, 3
br i1 %36, label %37, label %16
37: ; preds = %33
%38 = load i32, i32* %6
%39 = load i32, i32* %5
%40 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 %38, i32 %39, i8* %0)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %37
store i8* null, i8** %7
br label %43
43: ; preds = %16, %37, %42
%44 = load i8*, i8** %2
%45 = call i32 @free(i8* %44)
%46 = call i32 @fclose(i32* %14)
%47 = load i8*, i8** %7
br label %48
48: ; preds = %1, %43
%49 = phi i8* [ %47, %43 ], [ null, %1 ]
ret i8* %49
}