#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, "Hardware", 8) == 0) {
      if (strstr(line, "BCM2709") != NULL) {
        fclose(cpuFd);
        return 2;
      } 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     1213 <checkPiModel+0xc3>
lea    -0x90(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    120e <checkPiModel+0xbe>
lea    -0x90(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11f9 <checkPiModel+0xa9>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x2,-0x4(%rbp)
jmp    1223 <checkPiModel+0xd3>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1223 <checkPiModel+0xd3>
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   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe9d(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rbx
lea    0xe94(%rip),%r15
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x78,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d2 <checkPiModel+0x82>
mov    %rbx,%rdi
mov    %r15,%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    %rax,%rbx
mov    %r14,%rdi
call   1040 <fclose@plt>
cmp    $0x1,%rbx
mov    $0x2,%eax
sbb    $0x0,%eax
jmp    11dc <checkPiModel+0x8c>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
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"Hardware\00"
@.str.3 = [8 x i8] c"BCM2709\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 = %27, %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 %28
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 %27
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 ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
store i32 2, i32* %1
br label %31
24: ; preds = %17
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
store i32 1, i32* %1
br label %31
27: ; preds = %13
br label %8
28: ; preds = %8
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %1
br label %31
31: ; preds = %28, %24, %21
%32 = load i32, i32* %1
ret i32 %32
}

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"Hardware\00"
@.str.3 = [8 x i8] c"BCM2709\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 %15, 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 ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i32* %11, null
%13 = call i32 @fclose(i32* %3)
%14 = select i1 %12, i32 1, i32 2
br label %17
15: ; preds = %4
%16 = call i32 @fclose(i32* %3)
br label %17
17: ; preds = %10, %15
%18 = phi i32 [ 0, %15 ], [ %14, %10 ]
ret i32 %18
}