#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);
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(void) {
  char *line = NULL;
  size_t llen = 0;
  int found = 0, n;
  char vendor[30];
  int model, fam;
  char *res = NULL;
  FILE *f = fopen("/proc/cpuinfo", "r");
  if (!f)
    return NULL;
  while (getline(&line, &llen, f) > 0) {
    if (sscanf(line, "vendor_id : %30s", 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-core", vendor, fam, model);
      if (n < 0)
        res = NULL;
      break;
    }
  }
  free(line);
  fclose(f);
  return res;
}


x86 assembly (clang, -O0):
<get_cpu_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x50(%rbp)
lea    0xe72(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11b6 <get_cpu_str+0x56>
movq   $0x0,-0x8(%rbp)
jmp    12c0 <get_cpu_str+0x160>
jmp    11bb <get_cpu_str+0x5b>
mov    -0x58(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
cmp    $0x0,%rax
jle    12a6 <get_cpu_str+0x146>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1203 <get_cpu_str+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1262 <get_cpu_str+0x102>
mov    -0x10(%rbp),%rdi
lea    0xe13(%rip),%rsi
lea    -0x44(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1230 <get_cpu_str+0xd0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125d <get_cpu_str+0xfd>
mov    -0x10(%rbp),%rdi
lea    0xdf1(%rip),%rsi
lea    -0x48(%rbp),%rdx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1258 <get_cpu_str+0xf8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125d <get_cpu_str+0xfd>
jmp    1262 <get_cpu_str+0x102>
cmpl   $0x3,-0x1c(%rbp)
jne    12a1 <get_cpu_str+0x141>
lea    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%ecx
mov    -0x44(%rbp),%r8d
lea    -0x50(%rbp),%rdi
lea    0xdba(%rip),%rsi
call   1060 <asprintf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    129c <get_cpu_str+0x13c>
movq   $0x0,-0x50(%rbp)
jmp    12a6 <get_cpu_str+0x146>
jmp    11bb <get_cpu_str+0x5b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpu_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe71(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
test   %rbx,%rbx
je     1280 <get_cpu_str+0x120>
mov    %rsp,%r14
lea    0x18(%rsp),%r15
lea    0x20(%rsp),%r13
xor    %ebp,%ebp
jmp    11c8 <get_cpu_str+0x68>
nopw   0x0(%rax,%rax,1)
add    %r12d,%ebp
cmp    $0x3,%ebp
je     123e <get_cpu_str+0xde>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
test   %rax,%rax
jle    126a <get_cpu_str+0x10a>
mov    (%rsp),%rdi
lea    0xe26(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    $0x1,%r12d
cmp    $0x1,%eax
je     11c0 <get_cpu_str+0x60>
mov    (%rsp),%rdi
lea    0xe17(%rip),%rsi
lea    0x14(%rsp),%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11c0 <get_cpu_str+0x60>
mov    (%rsp),%rdi
lea    0xe06(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
xor    %r12d,%r12d
cmp    $0x1,%eax
sete   %r12b
jmp    11c0 <get_cpu_str+0x60>
mov    0x10(%rsp),%ecx
mov    0x14(%rsp),%r8d
lea    0xdee(%rip),%rsi
lea    0x8(%rsp),%rdi
lea    0x20(%rsp),%rdx
call   1060 <asprintf@plt>
test   %eax,%eax
jns    126a <get_cpu_str+0x10a>
movq   $0x0,0x8(%rsp)
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rax
add    $0x48,%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 : %30s\00"
@.str.3 = [11 x i8] c"model : %d\00"
@.str.4 = [16 x i8] c"cpu family : %d\00"
@.str.5 = [14 x i8] c"%s-%d-%X-core\00"
define i8* @get_cpu_str() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca [30 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store i8* null, i8** %2
store i64 0, i64* %3
store i32 0, i32* %4
store i8* null, i8** %9
%11 = 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* %11, i32** %10
%12 = load i32*, i32** %10
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %0
store i8* null, i8** %1
br label %63
15: ; preds = %0
br label %16
16: ; preds = %56, %15
%17 = load i32*, i32** %10
%18 = call i64 @getline(i8** %2, i64* %3, i32* %17)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %57
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%23 = call i32 (i8*, i8*, ...) @sscanf(i8* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %44
28: ; preds = %20
%29 = load i8*, i8** %2
%30 = call i32 (i8*, i8*, ...) @sscanf(i8* %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %43
35: ; preds = %28
%36 = load i8*, i8** %2
%37 = call i32 (i8*, i8*, ...) @sscanf(i8* %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32* %8)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* %4
%41 = add nsw i32 %40, 1
store i32 %41, i32* %4
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42, %32
br label %44
44: ; preds = %43, %25
%45 = load i32, i32* %4
%46 = icmp eq i32 %45, 3
br i1 %46, label %47, label %56
47: ; preds = %44
%48 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%49 = load i32, i32* %8
%50 = load i32, i32* %7
%51 = call i32 @asprintf(i8** %9, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %48, i32 %49, i32 %50)
store i32 %51, i32* %5
%52 = load i32, i32* %5
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %47
store i8* null, i8** %9
br label %55
55: ; preds = %54, %47
br label %57
56: ; preds = %44
br label %16
57: ; preds = %55, %16
%58 = load i8*, i8** %2
%59 = call i32 @free(i8* %58)
%60 = load i32*, i32** %10
%61 = call i32 @fclose(i32* %60)
%62 = load i8*, i8** %9
store i8* %62, i8** %1
br label %63
63: ; preds = %57, %14
%64 = load i8*, i8** %1
ret i8* %64
}

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