#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
char *strstr(char *, char *);
int is_a_pi(void) {
  FILE *fp;
  char buffer[4096];
  size_t bytes_read;
  char *match;
  fp = fopen("/proc/cpuinfo", "r");
  bytes_read = fread(buffer, 1, sizeof(buffer), fp);
  fclose(fp);
  if (bytes_read == 0 || bytes_read == sizeof(buffer)) {
    printf("Read of /proc/cpuinfo failed\n");
    return 0;
  }
  buffer[bytes_read] = '\0';
  match = strstr(buffer, "BCM2708");
  if (match == NULL)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_a_pi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
lea    0xe9e(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x1018(%rbp)
je     11bb <is_a_pi+0x6b>
cmpq   $0x1000,-0x1018(%rbp)
jne    11d3 <is_a_pi+0x83>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    121d <is_a_pi+0xcd>
mov    -0x1018(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x1020(%rbp)
cmpq   $0x0,-0x1020(%rbp)
jne    1216 <is_a_pi+0xc6>
movl   $0x0,-0x4(%rbp)
jmp    121d <is_a_pi+0xcd>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_a_pi>:
push   %r14
push   %rbx
sub    $0x1008,%rsp
lea    0xe9f(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   $0xffffffffffffefff,%r14
je     11ba <is_a_pi+0x6a>
movb   $0x0,(%rsp,%r14,1)
lea    0xe6b(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    11c8 <is_a_pi+0x78>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Read of /proc/cpuinfo failed\0A\00"
@.str.3 = [8 x i8] c"BCM2708\00"
define i32 @is_a_pi() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [4096 x i8]
%4 = alloca i64
%5 = alloca i8*
%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 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = load i32*, i32** %2
%9 = call i64 @fread(i8* %7, i32 1, i32 4096, i32* %8)
store i64 %9, i64* %4
%10 = load i32*, i32** %2
%11 = call i32 @fclose(i32* %10)
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %0
%15 = load i64, i64* %4
%16 = icmp eq i64 %15, 4096
br i1 %16, label %17, label %19
17: ; preds = %14, %0
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %28
19: ; preds = %14
%20 = load i64, i64* %4
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%23 = call i8* @strstr(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 0, i32* %1
br label %28
27: ; preds = %19
store i32 1, i32* %1
br label %28
28: ; preds = %27, %26, %17
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"BCM2708\00"
@str = [29 x i8] c"Read of /proc/cpuinfo failed\00"
define i32 @is_a_pi() {
%1 = alloca [4096 x i8]
%2 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%3 = 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))
%4 = call i64 @fread(i8* %2, i32 1, i32 4096, i32* %3)
%5 = tail call i32 @fclose(i32* %3)
%6 = and i64 %4, -4097
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %4
store i8 0, i8* %11
%12 = call i8* @strstr(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp ne i8* %12, null
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ 0, %8 ], [ %14, %10 ]
ret i32 %16
}