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


x86 assembly (clang, -O0):
<get_cpuinfo_revision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1198 <get_cpuinfo_revision+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <get_cpuinfo_revision+0xcf>
jmp    119d <get_cpuinfo_revision+0x3d>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11bb <get_cpuinfo_revision+0x5b>
jmp    121f <get_cpuinfo_revision+0xbf>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1070 <sscanf@plt>
lea    -0x810(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121a <get_cpuinfo_revision+0xba>
movl   $0x1,-0x4(%rbp)
jmp    122f <get_cpuinfo_revision+0xcf>
jmp    119d <get_cpuinfo_revision+0x3d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cpuinfo_revision>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
lea    0xe89(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f1 <get_cpuinfo_revision+0x91>
mov    %rax,%rbx
lea    0x400(%rsp),%r14
lea    0xe76(%rip),%r15
mov    %rsp,%r12
lea    0xe7a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11f8 <get_cpuinfo_revision+0x98>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1070 <sscanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11b0 <get_cpuinfo_revision+0x50>
mov    $0x1,%eax
jmp    1202 <get_cpuinfo_revision+0xa2>
mov    $0xffffffff,%eax
jmp    1202 <get_cpuinfo_revision+0xa2>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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 = [6 x i8] c"sun7i\00"
define i32 @get_cpuinfo_revision() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%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 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 -1, i32* %1
br label %30
9: ; preds = %0
br label %10
10: ; preds = %26, %9
%11 = load i32*, i32** %2
%12 = call i32 @feof(i32* %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = load i32*, i32** %2
%18 = call i8* @fgets(i8* %16, i32 1024, i32* %17)
store i8* %18, i8** %5
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %15
store i32 1, i32* %1
br label %30
26: ; preds = %15
br label %10
27: ; preds = %10
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
store i32 0, i32* %1
br label %30
30: ; preds = %27, %25, %8
%31 = load i32, i32* %1
ret i32 %31
}

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 = [6 x i8] c"sun7i\00"
define i32 @get_cpuinfo_revision() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 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 %17, label %7
7: ; preds = %0, %10
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = call i8* @fgets(i8* %3, i32 1024, i32* %5)
%12 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %7
15: ; preds = %7
%16 = call i32 @fclose(i32* %5)
br label %17
17: ; preds = %10, %0, %15
%18 = phi i32 [ 0, %15 ], [ -1, %0 ], [ 1, %10 ]
ret i32 %18
}