#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
char *get_cpuinfo_revision(char *revision) {
  FILE *fp;
  char buffer[1024];
  char hardware[1024];
  int rpi_found = 0;
  if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
    return 0;
  while (!feof(fp)) {
    fgets(buffer, sizeof(buffer), fp);
    sscanf(buffer, "Hardware	: %s", hardware);
    if (strcmp(hardware, "BCM2708") == 0)
      rpi_found = 1;
    else if (strcmp(hardware, "BCM2709") == 0)
      rpi_found = 1;
    sscanf(buffer, "Revision	: %s", revision);
  }
  fclose(fp);
  if (!rpi_found)
    revision = NULL;
  return revision;
}


x86 assembly (clang, -O0):
<get_cpuinfo_revision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x824(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a7 <get_cpuinfo_revision+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1293 <get_cpuinfo_revision+0x133>
jmp    11ac <get_cpuinfo_revision+0x4c>
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ca <get_cpuinfo_revision+0x6a>
jmp    126d <get_cpuinfo_revision+0x10d>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1070 <sscanf@plt>
lea    -0x820(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1225 <get_cpuinfo_revision+0xc5>
movl   $0x1,-0x824(%rbp)
jmp    1251 <get_cpuinfo_revision+0xf1>
lea    -0x820(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    124c <get_cpuinfo_revision+0xec>
movl   $0x1,-0x824(%rbp)
jmp    1251 <get_cpuinfo_revision+0xf1>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdcb(%rip),%rsi
call   1070 <sscanf@plt>
jmp    11ac <get_cpuinfo_revision+0x4c>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x824(%rbp)
jne    128b <get_cpuinfo_revision+0x12b>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpuinfo_revision>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdi,%r14
lea    0xe85(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1249 <get_cpuinfo_revision+0xe9>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11ac <get_cpuinfo_revision+0x4c>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1249 <get_cpuinfo_revision+0xe9>
xor    %ebp,%ebp
lea    0x400(%rsp),%r15
mov    %rsp,%r13
jmp    11e1 <get_cpuinfo_revision+0x81>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xe64(%rip),%rsi
mov    %r14,%rdx
call   1070 <sscanf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
mov    %r12d,%ebp
test   %eax,%eax
jne    123c <get_cpuinfo_revision+0xdc>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %r15,%rdi
lea    0xe15(%rip),%rsi
mov    %r13,%rdx
call   1070 <sscanf@plt>
mov    %r13,%rdi
lea    0xe11(%rip),%rsi
call   1050 <strcmp@plt>
mov    $0x1,%r12d
test   %rax,%rax
je     11c0 <get_cpuinfo_revision+0x60>
mov    %r13,%rdi
lea    0xdff(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%ebp
mov    %ebp,%r12d
jmp    11c0 <get_cpuinfo_revision+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r12d,%r12d
jne    124c <get_cpuinfo_revision+0xec>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"Hardware\09: %s\00"
@.str.3 = [8 x i8] c"BCM2708\00"
@.str.4 = [8 x i8] c"BCM2709\00"
@.str.5 = [14 x i8] c"Revision\09: %s\00"
define i8* @get_cpuinfo_revision(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
%8 = 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* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %46
11: ; preds = %1
br label %12
12: ; preds = %34, %11
%13 = load i32*, i32** %4
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %38
17: ; preds = %12
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i32*, i32** %4
%20 = call i32 @fgets(i8* %18, i32 1024, i32* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %17
store i32 1, i32* %7
br label %34
28: ; preds = %17
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %7
br label %33
33: ; preds = %32, %28
br label %34
34: ; preds = %33, %27
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%36 = load i8*, i8** %3
%37 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %12
38: ; preds = %12
%39 = load i32*, i32** %4
%40 = call i32 @fclose(i32* %39)
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 0
br i1 %42, label %44, label %43
43: ; preds = %38
store i8* null, i8** %3
br label %44
44: ; preds = %43, %38
%45 = load i8*, i8** %3
store i8* %45, i8** %2
br label %46
46: ; preds = %44, %10
%47 = load i8*, i8** %2
ret i8* %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"Hardware\09: %s\00"
@.str.3 = [8 x i8] c"BCM2708\00"
@.str.4 = [8 x i8] c"BCM2709\00"
@.str.5 = [14 x i8] c"Revision\09: %s\00"
define i8* @get_cpuinfo_revision(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = 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))
%7 = icmp eq i32* %6, null
br i1 %7, label %32, label %8
8: ; preds = %1
%9 = call i32 @feof(i32* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @fclose(i32* %6)
br label %31
13: ; preds = %8, %23
%14 = phi i32 [ %24, %23 ], [ 0, %8 ]
%15 = call i32 @fgets(i8* %4, i32 1024, i32* %6)
%16 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%17 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 1, i32 %14
br label %23
23: ; preds = %19, %13
%24 = phi i32 [ 1, %13 ], [ %22, %19 ]
%25 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%26 = call i32 @feof(i32* %6)
%27 = icmp eq i32 %26, 0
br i1 %27, label %13, label %28
28: ; preds = %23
%29 = call i32 @fclose(i32* %6)
%30 = icmp eq i32 %24, 0
br i1 %30, label %31, label %32
31: ; preds = %11, %28
br label %32
32: ; preds = %31, %28, %1
%33 = phi i8* [ null, %1 ], [ null, %31 ], [ %0, %28 ]
ret i8* %33
}