#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*/ *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, "Warning: can't parse /proc/cmdline\n");
    fprintf(stderr, "Assuming Pi3B\n");
    result = 0xa22082;
  }
  return result;
}


x86 assembly (clang, -O0):
<rpi_version>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0xffffffff,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     1262 <rpi_version+0x102>
jmp    119f <rpi_version+0x3f>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11ed <rpi_version+0x8d>
lea    -0x110(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
je     11e8 <rpi_version+0x88>
jmp    11ed <rpi_version+0x8d>
jmp    119f <rpi_version+0x3f>
cmpl   $0x0,-0x4(%rbp)
jge    1256 <rpi_version+0xf6>
mov    -0x118(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rdx
lea    0xdf8(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    1251 <rpi_version+0xf1>
lea    -0x110(%rbp),%rdi
lea    0xdf6(%rip),%rsi
lea    -0x4(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x0,%rax
je     124c <rpi_version+0xec>
jmp    1251 <rpi_version+0xf1>
jmp    1203 <rpi_version+0xa3>
jmp    1256 <rpi_version+0xf6>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x4(%rbp)
jge    129d <rpi_version+0x13d>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xa22082,-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    0xe81(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1236 <rpi_version+0xd6>
mov    %rax,%r15
lea    0xe72(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe6c(%rip),%r12
lea    0xc(%rsp),%r13
nop
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    11d6 <rpi_version+0x76>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     11b0 <rpi_version+0x50>
cmpl   $0x0,0xc(%rsp)
jns    1226 <rpi_version+0xc6>
mov    %r15,%rdi
call   1040 <rewind@plt>
lea    0xe24(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe32(%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    1226 <rpi_version+0xc6>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
test   %rax,%rax
je     1200 <rpi_version+0xa0>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jns    125e <rpi_version+0xfe>
mov    0x2da3(%rip),%rbx
mov    (%rbx),%edi
lea    0xdf8(%rip),%rsi
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe0e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xa22082,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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 = [36 x i8] c"Warning: can't parse /proc/cmdline\0A\00"
@.str.6 = [15 x i8] c"Assuming Pi3B\0A\00"
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 ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32 10625154, i32* %1
br label %48
48: ; preds = %43, %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 = [36 x i8] c"Warning: can't parse /proc/cmdline\0A\00"
@.str.6 = [15 x i8] c"Assuming Pi3B\0A\00"
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 ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %33
33: ; preds = %28, %24
%34 = phi i32 [ 10625154, %28 ], [ %26, %24 ]
ret i32 %34
}