#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ *strstr(char *, char *);
int checkPiModel() {
  FILE *cpuFd;
  char line[120];
  if ((cpuFd = fopen("/proc/cpuinfo", "r")) == NULL)
    ;
  while (fgets(line, 120, cpuFd) != NULL)
    if (strncmp(line, "Revision", 8) == 0) {
      if (strstr(line, "a01041") != NULL || strstr(line, "a21041") != NULL) {
        fclose(cpuFd);
        return 2;
      } else if (strstr(line, "a02082") != NULL ||
                 strstr(line, "a22082") != NULL) {
        fclose(cpuFd);
        return 3;
      } else {
        fclose(cpuFd);
        return 1;
      }
    }
  fclose(cpuFd);
  return 0;
}


x86 assembly (clang, -O0):
<checkPiModel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1181 <checkPiModel+0x31>
jmp    1181 <checkPiModel+0x31>
jmp    1186 <checkPiModel+0x36>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x78,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     127f <checkPiModel+0x12f>
lea    -0x90(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    127a <checkPiModel+0x12a>
lea    -0x90(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
jne    1201 <checkPiModel+0xb1>
lea    -0x90(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1216 <checkPiModel+0xc6>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x2,-0x4(%rbp)
jmp    128f <checkPiModel+0x13f>
lea    -0x90(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
jne    1250 <checkPiModel+0x100>
lea    -0x90(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1265 <checkPiModel+0x115>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x3,-0x4(%rbp)
jmp    128f <checkPiModel+0x13f>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    128f <checkPiModel+0x13f>
jmp    1186 <checkPiModel+0x36>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkPiModel>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rbp
lea    0xe95(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x78,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     120f <checkPiModel+0xbf>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1180 <checkPiModel+0x30>
lea    0xe68(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
mov    $0x2,%ebp
test   %rax,%rax
jne    1211 <checkPiModel+0xc1>
lea    0xe56(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
jne    1211 <checkPiModel+0xc1>
lea    0xe49(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
mov    $0x3,%ebp
test   %rax,%rax
jne    1211 <checkPiModel+0xc1>
lea    0xe37(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,1),%ebp
add    $0x1,%ebp
jmp    1211 <checkPiModel+0xc1>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"Revision\00"
@.str.3 = [7 x i8] c"a01041\00"
@.str.4 = [7 x i8] c"a21041\00"
@.str.5 = [7 x i8] c"a02082\00"
@.str.6 = [7 x i8] c"a22082\00"
define i32 @checkPiModel() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [120 x i8]
%4 = 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* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %0
br label %7
7: ; preds = %6, %0
br label %8
8: ; preds = %42, %7
%9 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32* @fgets(i8* %9, i32 120, i32* %10)
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %43
13: ; preds = %8
%14 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%15 = call i64 @strncmp(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%19 = call i32* @strstr(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp ne i32* %19, null
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%23 = call i32* @strstr(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %21, %17
%26 = load i32*, i32** %2
%27 = call i32 @fclose(i32* %26)
store i32 2, i32* %1
br label %46
28: ; preds = %21
%29 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%30 = call i32* @strstr(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp ne i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = getelementptr inbounds [120 x i8], [120 x i8]* %3, i64 0, i64 0
%34 = call i32* @strstr(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %32, %28
%37 = load i32*, i32** %2
%38 = call i32 @fclose(i32* %37)
store i32 3, i32* %1
br label %46
39: ; preds = %32
%40 = load i32*, i32** %2
%41 = call i32 @fclose(i32* %40)
store i32 1, i32* %1
br label %46
42: ; preds = %13
br label %8
43: ; preds = %8
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %1
br label %46
46: ; preds = %43, %39, %36, %25
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"Revision\00"
@.str.3 = [7 x i8] c"a01041\00"
@.str.4 = [7 x i8] c"a21041\00"
@.str.5 = [7 x i8] c"a02082\00"
@.str.6 = [7 x i8] c"a22082\00"
define i32 @checkPiModel() {
%1 = alloca [120 x i8]
%2 = getelementptr inbounds [120 x i8], [120 x i8]* %1, i64 0, i64 0
%3 = 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))
br label %4
4: ; preds = %7, %0
%5 = call i32* @fgets(i8* %2, i32 120, i32* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %4
10: ; preds = %7
%11 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = call i32* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%21 = icmp eq i32* %20, null
%22 = select i1 %21, i32 1, i32 3
br label %23
23: ; preds = %4, %19, %16, %10, %13
%24 = phi i32 [ 2, %13 ], [ 2, %10 ], [ 3, %16 ], [ %22, %19 ], [ 0, %4 ]
%25 = call i32 @fclose(i32* %3)
ret i32 %24
}