#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 /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int rpi_version(void) {
  int result = -1;
  char string[256];
  FILE *fp;
  fp = fopen("/proc/cmdline", "r");
  if (fp) {
    while (fscanf(fp, "%255s", string) == 1) {
      if (sscanf(string, "bcm2708.boardrev=%i", &result))
        break;
    }
    if (result < 0) {
      rewind(fp);
      while (fscanf(fp, "%255s", string) == 1)
        if (sscanf(string, "bcm2709.boardrev=%i", &result))
          break;
    }
    fclose(fp);
  }
  if (result < 0) {
    fprintf(stderr, "can't parse /proc/cmdline\n");
    exit(EXIT_FAILURE);
  }
  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     1272 <rpi_version+0x102>
jmp    11af <rpi_version+0x3f>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11fd <rpi_version+0x8d>
lea    -0x110(%rbp),%rdi
lea    0xe36(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
je     11f8 <rpi_version+0x88>
jmp    11fd <rpi_version+0x8d>
jmp    11af <rpi_version+0x3f>
cmpl   $0x0,-0x4(%rbp)
jge    1266 <rpi_version+0xf6>
mov    -0x118(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xde8(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1261 <rpi_version+0xf1>
lea    -0x110(%rbp),%rdi
lea    0xde6(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
je     125c <rpi_version+0xec>
jmp    1261 <rpi_version+0xf1>
jmp    1213 <rpi_version+0xa3>
jmp    1266 <rpi_version+0xf6>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x4(%rbp)
jge    129f <rpi_version+0x12f>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xdb2(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
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     1257 <rpi_version+0xe7>
mov    %rax,%r15
lea    0xe62(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe5c(%rip),%r12
lea    0xc(%rsp),%r13
nop
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11e6 <rpi_version+0x76>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     11c0 <rpi_version+0x50>
cmpl   $0x0,0xc(%rsp)
jns    1236 <rpi_version+0xc6>
mov    %r15,%rdi
call   1040 <rewind@plt>
lea    0xe14(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe22(%rip),%r12
lea    0xc(%rsp),%r13
nopl   (%rax)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1236 <rpi_version+0xc6>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     1210 <rpi_version+0xa0>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
js     1257 <rpi_version+0xe7>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%255s\00"
@.str.3 = [20 x i8] c"bcm2708.boardrev=%i\00"
@.str.4 = [20 x i8] c"bcm2709.boardrev=%i\00"
@stderr = global i32 0
@.str.5 = [27 x i8] c"can't parse /proc/cmdline\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 %40
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 @sscanf(i8* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%16 = icmp ne 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
%20 = load i32, i32* %1
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i32*, i32** %3
%24 = call i32 @rewind(i32* %23)
br label %25
25: ; preds = %35, %22
%26 = load i32*, i32** %3
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%28 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%32 = call i64 @sscanf(i8* %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %30
br label %36
35: ; preds = %30
br label %25
36: ; preds = %34, %25
br label %37
37: ; preds = %36, %19
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %0
%41 = load i32, i32* %1
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %40
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"%255s\00"
@.str.3 = [20 x i8] c"bcm2708.boardrev=%i\00"
@.str.4 = [20 x i8] c"bcm2709.boardrev=%i\00"
@stderr = global i32 0
@.str.5 = [27 x i8] c"can't parse /proc/cmdline\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 %28, 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 @sscanf(i8* %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %10, %7
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = call i32 @rewind(i32* %5)
br label %18
18: ; preds = %21, %16
%19 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i64 @sscanf(i8* %4, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %18, label %24
24: ; preds = %21, %18, %13
%25 = call i32 @fclose(i32* %5)
%26 = load i32, i32* %1
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %0, %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %24
ret i32 %26
}