#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 BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, ...);
scalar_t__ strncmp(char *, char *, int);
int detect_cpu(void) {
  FILE *fff;
  int family, model = -1;
  char buffer[BUFSIZ], *result;
  char vendor[BUFSIZ];
  fff = fopen("/proc/cpuinfo", "r");
  if (fff == NULL)
    return -1;
  while (1) {
    result = fgets(buffer, BUFSIZ, fff);
    if (result == NULL)
      break;
    if (!strncmp(result, "vendor_id", 8)) {
      sscanf(result, "%*s%*s%s", vendor);
      if (strncmp(vendor, "GenuineIntel", 12)) {
        printf("%s not an Intel chip\n", vendor);
        return -1;
      }
    }
    if (!strncmp(result, "cpu family", 10)) {
      sscanf(result, "%*s%*s%*s%d", &family);
      if (family != 6) {
        printf("Wrong CPU family %d\n", family);
        return -1;
      }
    }
    if (!strncmp(result, "model", 5)) {
      sscanf(result, "%*s%*s%d", &model);
    }
  }
  fclose(fff);
  return model;
}


x86 assembly (clang, -O0):
<detect_cpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0xffffffff,-0x18(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    0xe40(%rip),%rdi
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ee <detect_cpu+0x8e>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1358 <detect_cpu+0x1f8>
jmp    11f3 <detect_cpu+0x93>
jmp    11f8 <detect_cpu+0x98>
mov    -0x50(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1060 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1222 <detect_cpu+0xc2>
jmp    1342 <detect_cpu+0x1e2>
mov    -0x30(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a0 <detect_cpu+0x140>
mov    -0x48(%rbp),%rdx
mov    -0x30(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1070 <sscanf@plt>
mov    -0x48(%rbp),%rdi
lea    0xdc1(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     129b <detect_cpu+0x13b>
mov    -0x48(%rbp),%rsi
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1358 <detect_cpu+0x1f8>
jmp    12a0 <detect_cpu+0x140>
mov    -0x30(%rbp),%rdi
lea    0xd9b(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1308 <detect_cpu+0x1a8>
mov    -0x30(%rbp),%rdi
lea    0xd87(%rip),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
cmpl   $0x6,-0x14(%rbp)
je     1303 <detect_cpu+0x1a3>
mov    -0x14(%rbp),%esi
lea    0xd74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    1358 <detect_cpu+0x1f8>
jmp    1308 <detect_cpu+0x1a8>
mov    -0x30(%rbp),%rdi
lea    0xd5f(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    133d <detect_cpu+0x1dd>
mov    -0x30(%rbp),%rdi
lea    0xd22(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1070 <sscanf@plt>
jmp    11f3 <detect_cpu+0x93>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_cpu>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%r14
movl   $0xffffffff,-0x2c(%rbp)
mov    0x2e5e(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x0(%r13),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe4d(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    $0xffffffff,%eax
test   %r12,%r12
je     130a <detect_cpu+0x1aa>
mov    %r14,-0x38(%rbp)
mov    0x0(%r13),%esi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12cf <detect_cpu+0x16f>
mov    %rax,%r13
lea    0xe7c(%rip),%r14
jmp    1220 <detect_cpu+0xc0>
nopl   0x0(%rax,%rax,1)
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1060 <fgets@plt>
mov    %rax,%r13
test   %rax,%rax
je     12cf <detect_cpu+0x16f>
mov    %r13,%rdi
lea    0xde6(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1266 <detect_cpu+0x106>
mov    %r13,%rdi
lea    0xdd7(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    %r15,%rdi
lea    0xdcc(%rip),%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    12e0 <detect_cpu+0x180>
mov    %r13,%rdi
lea    0xdd6(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    129c <detect_cpu+0x13c>
mov    %r13,%rdi
lea    0xdc8(%rip),%rsi
lea    -0x3c(%rbp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    -0x3c(%rbp),%esi
cmp    $0x6,%esi
jne    12f3 <detect_cpu+0x193>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1200 <detect_cpu+0xa0>
mov    %r13,%rdi
lea    0xd95(%rip),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
jmp    1200 <detect_cpu+0xa0>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    -0x38(%rbp),%r14
jmp    130a <detect_cpu+0x1aa>
lea    0xd49(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1301 <detect_cpu+0x1a1>
lea    0xd63(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x38(%rbp),%r14
mov    $0xffffffff,%eax
mov    %r14,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"vendor_id\00"
@.str.3 = [9 x i8] c"%*s%*s%s\00"
@.str.4 = [13 x i8] c"GenuineIntel\00"
@.str.5 = [22 x i8] c"%s not an Intel chip\0A\00"
@.str.6 = [11 x i8] c"cpu family\00"
@.str.7 = [12 x i8] c"%*s%*s%*s%d\00"
@.str.8 = [21 x i8] c"Wrong CPU family %d\0A\00"
@.str.9 = [6 x i8] c"model\00"
@.str.10 = [9 x i8] c"%*s%*s%d\00"
define i32 @detect_cpu() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 -1, i32* %4
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i32, i32* @BUFSIZ
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
store i64 %15, i64* %8
%17 = 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* %17, i32** %2
%18 = load i32*, i32** %2
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %0
store i32 -1, i32* %1
store i32 1, i32* %9
br label %67
21: ; preds = %0
br label %22
22: ; preds = %62, %21
br label %23
23: ; preds = %22
%24 = load i32, i32* @BUFSIZ
%25 = load i32*, i32** %2
%26 = call i8* @fgets(i8* %13, i32 %24, i32* %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %23
br label %63
30: ; preds = %23
%31 = load i8*, i8** %7
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 8)
%33 = icmp ne i64 %32, 0
br i1 %33, label %42, label %34
34: ; preds = %30
%35 = load i8*, i8** %7
%36 = call i32 (i8*, i8*, ...) @sscanf(i8* %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%37 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 12)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %16)
store i32 -1, i32* %1
store i32 1, i32* %9
br label %67
41: ; preds = %34
br label %42
42: ; preds = %41, %30
%43 = load i8*, i8** %7
%44 = call i64 @strncmp(i8* %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 10)
%45 = icmp ne i64 %44, 0
br i1 %45, label %55, label %46
46: ; preds = %42
%47 = load i8*, i8** %7
%48 = call i32 (i8*, i8*, ...) @sscanf(i8* %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32* %3)
%49 = load i32, i32* %3
%50 = icmp ne i32 %49, 6
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i32, i32* %3
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %52)
store i32 -1, i32* %1
store i32 1, i32* %9
br label %67
54: ; preds = %46
br label %55
55: ; preds = %54, %42
%56 = load i8*, i8** %7
%57 = call i64 @strncmp(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 5)
%58 = icmp ne i64 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %55
%60 = load i8*, i8** %7
%61 = call i32 (i8*, i8*, ...) @sscanf(i8* %60, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32* %4)
br label %62
62: ; preds = %59, %55
br label %22
63: ; preds = %29
%64 = load i32*, i32** %2
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* %4
store i32 %66, i32* %1
store i32 1, i32* %9
br label %67
67: ; preds = %63, %51, %39, %20
%68 = load i8*, i8** %5
%69 = load i32, i32* %1
ret i32 %69
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"vendor_id\00"
@.str.3 = [9 x i8] c"%*s%*s%s\00"
@.str.4 = [13 x i8] c"GenuineIntel\00"
@.str.5 = [22 x i8] c"%s not an Intel chip\0A\00"
@.str.6 = [11 x i8] c"cpu family\00"
@.str.7 = [12 x i8] c"%*s%*s%*s%d\00"
@.str.8 = [21 x i8] c"Wrong CPU family %d\0A\00"
@.str.9 = [6 x i8] c"model\00"
@.str.10 = [9 x i8] c"%*s%*s%d\00"
define i32 @detect_cpu() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 -1, i32* %2
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = load i32, i32* @BUFSIZ
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = 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))
%13 = icmp eq i32* %12, null
br i1 %13, label %49, label %14
14: ; preds = %0
%15 = load i32, i32* @BUFSIZ
%16 = call i8* @fgets(i8* %8, i32 %15, i32* %12)
%17 = icmp eq i8* %16, null
br i1 %17, label %46, label %18
18: ; preds = %14, %42
%19 = phi i8* [ %44, %42 ], [ %16, %14 ]
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%24 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 12)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %11)
br label %49
28: ; preds = %22, %18
%29 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 10)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32* %1)
%33 = load i32, i32* %1
%34 = icmp eq i32 %33, 6
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %33)
br label %49
37: ; preds = %31, %28
%38 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0), i32 5)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i32* %2)
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* @BUFSIZ
%44 = call i8* @fgets(i8* %8, i32 %43, i32* %12)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %18
46: ; preds = %42, %14
%47 = call i32 @fclose(i32* %12)
%48 = load i32, i32* %2
br label %49
49: ; preds = %0, %46, %35, %26
%50 = phi i32 [ %48, %46 ], [ -1, %35 ], [ -1, %26 ], [ -1, %0 ]
ret i32 %50
}