#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printd(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int RaspberryPiVersion(void) {
  FILE *ver_fd;
  int i_ret = 0;
  int ch;
  if ((ver_fd = fopen("/sys/firmware/devicetree/base/model", "r")) != NULL) {
    printf("Raspberry Pi Version: ");
    ch = getc(ver_fd);
    while (ch != EOF) {
      putchar(ch);
      ch = getc(ver_fd);
    }
    fclose(ver_fd);
    printf("\n");
  } else {
    printd("file /sys/firmware/devicetree/base/model does not exists\n");
    i_ret = -1;
  }
  return i_ret;
}


x86 assembly (clang, -O0):
<RaspberryPiVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11ed <RaspberryPiVersion+0x8d>
lea    0xe8f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
je     11d3 <RaspberryPiVersion+0x73>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x10(%rbp)
jmp    11a8 <RaspberryPiVersion+0x48>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe92(%rip),%rdi
call   1060 <printf@plt>
jmp    1200 <RaspberryPiVersion+0xa0>
lea    0xe49(%rip),%rdi
call   1040 <printd@plt>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RaspberryPiVersion>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xeb2(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ca <RaspberryPiVersion+0x6a>
mov    %rax,%rbx
lea    0xea0(%rip),%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    0x2e4e(%rip),%r14
cmp    (%r14),%eax
je     11b4 <RaspberryPiVersion+0x54>
nop
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r14),%eax
jne    11a0 <RaspberryPiVersion+0x40>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
jmp    11db <RaspberryPiVersion+0x7b>
lea    0xe6c(%rip),%rdi
call   1040 <printd@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [36 x i8] c"/sys/firmware/devicetree/base/model\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Raspberry Pi Version: \00"
@EOF = global i32 0
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [58 x i8] c"file /sys/firmware/devicetree/base/model does not exists\0A\00"
define i32 @RaspberryPiVersion() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 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** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %23
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32*, i32** %1
%9 = call i32 @getc(i32* %8)
store i32 %9, i32* %3
br label %10
10: ; preds = %14, %6
%11 = load i32, i32* %3
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i32 @putchar(i32 %15)
%17 = load i32*, i32** %1
%18 = call i32 @getc(i32* %17)
store i32 %18, i32* %3
br label %10
19: ; preds = %10
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %25
23: ; preds = %0
%24 = call i32 @printd(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %25
25: ; preds = %23, %19
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [36 x i8] c"/sys/firmware/devicetree/base/model\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"Raspberry Pi Version: \00"
@EOF = global i32 0
@.str.4 = [58 x i8] c"file /sys/firmware/devicetree/base/model does not exists\0A\00"
define i32 @RaspberryPiVersion() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %17, label %3
3: ; preds = %0
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @getc(i32* %1)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %3, %8
%9 = phi i32 [ %11, %8 ], [ %5, %3 ]
%10 = tail call i32 @putchar(i32 %9)
%11 = tail call i32 @getc(i32* %1)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %8
14: ; preds = %8, %3
%15 = tail call i32 @fclose(i32* %1)
%16 = tail call i32 @putchar(i32 10)
br label %19
17: ; preds = %0
%18 = tail call i32 @printd(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = phi i32 [ 0, %14 ], [ -1, %17 ]
ret i32 %20
}