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


x86 assembly (clang, -O0):
<get_cpuinfo_revision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x42c(%rbp)
movl   $0x0,-0x430(%rbp)
lea    0xe86(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a0 <get_cpuinfo_revision+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1298 <get_cpuinfo_revision+0x148>
jmp    11a5 <get_cpuinfo_revision+0x55>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1262 <get_cpuinfo_revision+0x112>
lea    -0x420(%rbp),%rdi
lea    -0x428(%rbp),%rdx
lea    0xe37(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    122e <get_cpuinfo_revision+0xde>
lea    -0x428(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     121f <get_cpuinfo_revision+0xcf>
lea    -0x428(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1229 <get_cpuinfo_revision+0xd9>
movl   $0x1,-0x42c(%rbp)
jmp    125d <get_cpuinfo_revision+0x10d>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdef(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1258 <get_cpuinfo_revision+0x108>
movl   $0x1,-0x430(%rbp)
jmp    125d <get_cpuinfo_revision+0x10d>
jmp    11a5 <get_cpuinfo_revision+0x55>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x42c(%rbp)
je     1285 <get_cpuinfo_revision+0x135>
cmpl   $0x0,-0x430(%rbp)
jne    1291 <get_cpuinfo_revision+0x141>
movl   $0x0,-0x4(%rbp)
jmp    1298 <get_cpuinfo_revision+0x148>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpuinfo_revision>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r14
lea    0xea5(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121c <get_cpuinfo_revision+0xdc>
mov    %rax,%r12
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1220 <get_cpuinfo_revision+0xe0>
xor    %ebp,%ebp
lea    0xe79(%rip),%r15
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r13
movl   $0x0,0x4(%rsp)
jmp    11dd <get_cpuinfo_revision+0x9d>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xe75(%rip),%rsi
mov    %r14,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
cmove  %eax,%ebp
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     122a <get_cpuinfo_revision+0xea>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <get_cpuinfo_revision+0x70>
movabs $0x383037324d4342,%rax
cmp    %rax,0x8(%rsp)
je     1212 <get_cpuinfo_revision+0xd2>
movabs $0x353338324d4342,%rax
cmp    %rax,0x8(%rsp)
jne    11c8 <get_cpuinfo_revision+0x88>
movl   $0x1,0x4(%rsp)
jmp    11c8 <get_cpuinfo_revision+0x88>
xor    %eax,%eax
jmp    1244 <get_cpuinfo_revision+0x104>
movl   $0x0,0x4(%rsp)
xor    %ebp,%ebp
mov    %r12,%rdi
call   1030 <fclose@plt>
cmpl   $0x0,0x4(%rsp)
setne  %al
test   %ebp,%ebp
setne  %cl
and    %al,%cl
movzbl %cl,%eax
add    $0x418,%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 = [15 x i8] c"Hardware\09: %7s\00"
@.str.3 = [8 x i8] c"BCM2708\00"
@.str.4 = [8 x i8] c"BCM2835\00"
@.str.5 = [18 x i8] c"Revision\09: %1023s\00"
define i32 @get_cpuinfo_revision(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [8 x i8]
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
store i32 0, i32* %8
%9 = 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* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %51
12: ; preds = %1
br label %13
13: ; preds = %40, %12
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = load i32*, i32** %4
%16 = call i64 @fgets(i8* %14, i32 1024, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27, %23
store i32 1, i32* %7
br label %32
32: ; preds = %31, %27
br label %40
33: ; preds = %18
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%35 = load i8*, i8** %3
%36 = call i32 @sscanf(i8* %34, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %35)
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 1, i32* %8
br label %39
39: ; preds = %38, %33
br label %40
40: ; preds = %39, %32
br label %13
41: ; preds = %13
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %46, %41
store i32 0, i32* %2
br label %51
50: ; preds = %46
store i32 1, i32* %2
br label %51
51: ; preds = %50, %49, %11
%52 = load i32, i32* %2
ret i32 %52
}

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