#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *);
scalar_t__ strcmp(char *, char *);
int GetRaspberryHwRevision(void) {
  FILE *fp;
  char line[32];
  char s[32];
  int i;
  fp = fopen("/proc/cpuinfo", "r");
  if (fp != NULL) {
    while (fgets(line, 32, fp)) {
      sscanf(line, "%s : %x", (char *)&s, &i);
      if (strcmp(s, "Revision") == 0) {
        if (i < 4)
          return 1;
        else
          return 2;
      }
    }
  } else {
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<GetRaspberryHwRevision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e9 <GetRaspberryHwRevision+0xa9>
jmp    116f <GetRaspberryHwRevision+0x2f>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x20,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11e4 <GetRaspberryHwRevision+0xa4>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe76(%rip),%rsi
lea    -0x54(%rbp),%rcx
call   1050 <sscanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11df <GetRaspberryHwRevision+0x9f>
cmpl   $0x4,-0x54(%rbp)
jge    11d3 <GetRaspberryHwRevision+0x93>
movl   $0x1,-0x4(%rbp)
jmp    11fc <GetRaspberryHwRevision+0xbc>
movl   $0x2,-0x4(%rbp)
jmp    11fc <GetRaspberryHwRevision+0xbc>
jmp    116f <GetRaspberryHwRevision+0x2f>
jmp    11f5 <GetRaspberryHwRevision+0xb5>
movl   $0x0,-0x4(%rbp)
jmp    11fc <GetRaspberryHwRevision+0xbc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetRaspberryHwRevision>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeab(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
test   %rbx,%rbx
je     11db <GetRaspberryHwRevision+0x9b>
lea    0x30(%rsp),%r12
lea    0xe99(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r13
lea    0xe90(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x20,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11d9 <GetRaspberryHwRevision+0x99>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
call   1050 <sscanf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1190 <GetRaspberryHwRevision+0x50>
xor    %ecx,%ecx
cmpl   $0x4,0xc(%rsp)
setl   %cl
mov    $0x2,%eax
sub    %ecx,%eax
jmp    11db <GetRaspberryHwRevision+0x9b>
xor    %eax,%eax
add    $0x58,%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 = [8 x i8] c"%s : %x\00"
@.str.3 = [9 x i8] c"Revision\00"
define i32 @GetRaspberryHwRevision() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = 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* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %29
9: ; preds = %0
br label %10
10: ; preds = %27, %9
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i64 @fgets(i8* %11, i32 32, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %10
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%17 = bitcast [32 x i8]* %4 to i8*
%18 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32* %5)
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp slt i32 %23, 4
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 1, i32* %1
br label %31
26: ; preds = %22
store i32 2, i32* %1
br label %31
27: ; preds = %15
br label %10
28: ; preds = %10
br label %30
29: ; preds = %0
store i32 0, i32* %1
br label %31
30: ; preds = %28
store i32 0, i32* %1
br label %31
31: ; preds = %30, %29, %26, %25
%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 = [8 x i8] c"%s : %x\00"
@.str.3 = [9 x i8] c"Revision\00"
define i32 @GetRaspberryHwRevision() {
%1 = alloca [32 x i8]
%2 = alloca [32 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = bitcast i32* %3 to i8*
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %20, label %9
9: ; preds = %0, %12
%10 = call i64 @fgets(i8* %4, i32 32, i32* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32* %3)
%14 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %9
16: ; preds = %12
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 4
%19 = select i1 %18, i32 1, i32 2
br label %20
20: ; preds = %9, %0, %16
%21 = phi i32 [ %19, %16 ], [ 0, %0 ], [ 0, %9 ]
ret i32 %21
}