#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*/ entry;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ strcasecmp(char *, char *);
int /*<<< orphan*/ strtok_r(char *, char *, char **);
int strtol(char *, int /*<<< orphan*/ *, int);
char *trimWhiteSpace(int /*<<< orphan*/);
int getRaspberryPiRevision() {
  int raspberryPiRevision = 0;
  FILE *fp = fopen("/proc/cpuinfo", "r");
  if (fp == NULL) {
    perror("/proc/cpuinfo");
    return raspberryPiRevision;
  }
  char entry[80];
  while (fgets(entry, sizeof(entry), fp) != NULL) {
    char *saveptr = NULL;
    char *key = trimWhiteSpace(strtok_r(entry, ":", &saveptr));
    char *value = trimWhiteSpace(strtok_r(NULL, ":", &saveptr));
    if (strcasecmp("Revision", key) == 0) {
      raspberryPiRevision = strtol(value, NULL, 16);
    }
  }
  fclose(fp);
  return raspberryPiRevision;
}


x86 assembly (clang, -O0):
<getRaspberryPiRevision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x8(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <getRaspberryPiRevision+0x4b>
lea    0xe45(%rip),%rdi
call   1090 <perror@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1275 <getRaspberryPiRevision+0xf5>
jmp    11d0 <getRaspberryPiRevision+0x50>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1266 <getRaspberryPiRevision+0xe6>
movq   $0x0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe11(%rip),%rsi
lea    -0x68(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %eax,%edi
call   10a0 <trimWhiteSpace@plt>
mov    %rax,-0x70(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf2(%rip),%rsi
lea    -0x68(%rbp),%rdx
call   1050 <strtok_r@plt>
mov    %eax,%edi
call   10a0 <trimWhiteSpace@plt>
mov    %rax,-0x78(%rbp)
mov    -0x70(%rbp),%rsi
lea    0xdd5(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1261 <getRaspberryPiRevision+0xe1>
mov    -0x78(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %eax,-0x8(%rbp)
jmp    11d0 <getRaspberryPiRevision+0x50>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getRaspberryPiRevision>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1287 <getRaspberryPiRevision+0x107>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1266 <getRaspberryPiRevision+0xe6>
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0xe3b(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbx
jmp    1205 <getRaspberryPiRevision+0x85>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     126c <getRaspberryPiRevision+0xec>
movq   $0x0,0x8(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
mov    %eax,%edi
call   10a0 <trimWhiteSpace@plt>
mov    %rax,%rbp
xor    %edi,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <strtok_r@plt>
mov    %eax,%edi
call   10a0 <trimWhiteSpace@plt>
mov    %rax,%r14
lea    0xdce(%rip),%rdi
mov    %rbp,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    11f0 <getRaspberryPiRevision+0x70>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %rax,(%rsp)
jmp    11f0 <getRaspberryPiRevision+0x70>
xor    %eax,%eax
mov    %rax,(%rsp)
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd72(%rip),%rdi
call   1090 <perror@plt>
xor    %eax,%eax
jmp    1278 <getRaspberryPiRevision+0xf8>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [9 x i8] c"Revision\00"
define i32 @getRaspberryPiRevision() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [80 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %2
%8 = 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* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %2
store i32 %13, i32* %1
br label %37
14: ; preds = %0
br label %15
15: ; preds = %32, %14
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i32* @fgets(i8* %16, i32 80, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %33
20: ; preds = %15
store i8* null, i8** %5
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%22 = call i32 @strtok_r(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%23 = call i8* @trimWhiteSpace(i32 %22)
store i8* %23, i8** %6
%24 = call i32 @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%25 = call i8* @trimWhiteSpace(i32 %24)
store i8* %25, i8** %7
%26 = load i8*, i8** %6
%27 = call i64 @strcasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = load i8*, i8** %7
%31 = call i32 @strtol(i8* %30, i32* null, i32 16)
store i32 %31, i32* %2
br label %32
32: ; preds = %29, %20
br label %15
33: ; preds = %15
%34 = load i32*, i32** %3
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %2
store i32 %36, i32* %1
br label %37
37: ; preds = %33, %11
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [9 x i8] c"Revision\00"
define i32 @getRaspberryPiRevision() {
%1 = alloca [80 x i8]
%2 = alloca i8*
%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))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %30
7: ; preds = %0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%9 = call i32* @fgets(i8* %8, i32 80, i32* %3)
%10 = icmp eq i32* %9, null
br i1 %10, label %27, label %11
11: ; preds = %7
%12 = bitcast i8** %2 to i8*
br label %13
13: ; preds = %11, %23
%14 = phi i32 [ 0, %11 ], [ %24, %23 ]
store i8* null, i8** %2
%15 = call i32 @strtok_r(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %2)
%16 = call i8* @trimWhiteSpace(i32 %15)
%17 = call i32 @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %2)
%18 = call i8* @trimWhiteSpace(i32 %17)
%19 = call i64 @strcasecmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = call i32 @strtol(i8* nocapture %18, i32* null, i32 16)
br label %23
23: ; preds = %21, %13
%24 = phi i32 [ %22, %21 ], [ %14, %13 ]
%25 = call i32* @fgets(i8* %8, i32 80, i32* %3)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %13
27: ; preds = %23, %7
%28 = phi i32 [ 0, %7 ], [ %24, %23 ]
%29 = call i32 @fclose(i32* %3)
br label %30
30: ; preds = %27, %5
%31 = phi i32 [ 0, %5 ], [ %28, %27 ]
ret i32 %31
}