#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int rpi_version() {
  int result = -1;
  char string[256];
  FILE *fp = fopen("/proc/cpuinfo", "r");
  if (fp) {
    while (fscanf(fp, "%255s", string) == 1)
      if (strcmp(string, "Revision") == 0)
        break;
    while (fscanf(fp, "%255s", string) == 1)
      if (sscanf(string, "%x", &result) == 1)
        break;
    fclose(fp);
  }
  if (result < 0) {
    fprintf(stderr, "can't parse /proc/cpuinfo\n");
    exit(EXIT_FAILURE);
  } else
    result &= ~(1 << 24 | 1 << 25);
  return result;
}


x86 assembly (clang, -O0):
<rpi_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     1257 <rpi_version+0xe7>
jmp    11af <rpi_version+0x3f>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11f9 <rpi_version+0x89>
lea    -0x110(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11f4 <rpi_version+0x84>
jmp    11f9 <rpi_version+0x89>
jmp    11af <rpi_version+0x3f>
jmp    11fe <rpi_version+0x8e>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xdfd(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    124b <rpi_version+0xdb>
lea    -0x110(%rbp),%rdi
lea    0xdf0(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1246 <rpi_version+0xd6>
jmp    124b <rpi_version+0xdb>
jmp    11fe <rpi_version+0x8e>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x4(%rbp)
jge    1284 <rpi_version+0x114>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xdb1(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%eax
and    $0xfcffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpi_version>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe71(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     124c <rpi_version+0xdc>
mov    %rax,%rbx
lea    0xe62(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe5c(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    11e3 <rpi_version+0x73>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c0 <rpi_version+0x50>
lea    0xe26(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe29(%rip),%r12
lea    0xc(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1226 <rpi_version+0xb6>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1200 <rpi_version+0x90>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     124c <rpi_version+0xdc>
and    $0xfcffffff,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%255s\00"
@.str.3 = [9 x i8] c"Revision\00"
@.str.4 = [3 x i8] c"%x\00"
@stderr = global i32 0
@.str.5 = [27 x i8] c"can't parse /proc/cpuinfo\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @rpi_version() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32*
store i32 -1, i32* %1
%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** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %34
7: ; preds = %0
br label %8
8: ; preds = %18, %7
%9 = load i32*, i32** %3
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i32 @fscanf(i32* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %8
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %19
18: ; preds = %13
br label %8
19: ; preds = %17, %8
br label %20
20: ; preds = %30, %19
%21 = load i32*, i32** %3
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%27 = call i32 @sscanf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %25
br label %31
30: ; preds = %25
br label %20
31: ; preds = %29, %20
%32 = load i32*, i32** %3
%33 = call i32 @fclose(i32* %32)
br label %34
34: ; preds = %31, %0
%35 = load i32, i32* %1
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
%43 = load i32, i32* %1
%44 = and i32 %43, -50331649
store i32 %44, i32* %1
br label %45
45: ; preds = %42
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%255s\00"
@.str.3 = [9 x i8] c"Revision\00"
@.str.4 = [3 x i8] c"%x\00"
@stderr = global i32 0
@.str.5 = [27 x i8] c"can't parse /proc/cpuinfo\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @rpi_version() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %24, label %7
7: ; preds = %0, %10
%8 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %10, %7
br label %14
14: ; preds = %13, %17
%15 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %14
20: ; preds = %14, %17
%21 = call i32 @fclose(i32* %5)
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %0, %20
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %20
%30 = and i32 %22, -50331649
ret i32 %30
}