#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strstr(char *, char *);
int get_cpuinfo_revision(char *revision_hex) {
  FILE *fp;
  char buffer[1024];
  char hardware[1024];
  int rpi_found = 0;
  if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
    return -1;
  while (!feof(fp)) {
    fgets(buffer, sizeof(buffer), fp);
    sscanf(buffer, "Hardware	: %s", hardware);
    if (strcmp(hardware, "BCM2708") == 0)
      rpi_found = 1;
    sscanf(buffer, "Revision	: %s", revision_hex);
  }
  fclose(fp);
  if (!rpi_found) {
    revision_hex = NULL;
    return 0;
  }
  char *pos = strstr(revision_hex, "1000");
  if (pos && pos - revision_hex == 0 && strlen(revision_hex) > 5) {
    strcpy(revision_hex, revision_hex + (strlen(revision_hex) - 4));
  }
  if ((strcmp(revision_hex, "0002") == 0) ||
      (strcmp(revision_hex, "0003") == 0)) {
    return 1;
  } else if ((strcmp(revision_hex, "0010") == 0)) {
    return 3;
  } else {
    return 2;
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_cpuinfo_revision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x824(%rbp)
lea    0xe50(%rip),%rdi
lea    0xe57(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d6 <get_cpuinfo_revision+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    138b <get_cpuinfo_revision+0x1fb>
jmp    11db <get_cpuinfo_revision+0x4b>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f9 <get_cpuinfo_revision+0x69>
jmp    126b <get_cpuinfo_revision+0xdb>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xded(%rip),%rsi
call   1090 <sscanf@plt>
lea    -0x820(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    124f <get_cpuinfo_revision+0xbf>
movl   $0x1,-0x824(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdc5(%rip),%rsi
call   1090 <sscanf@plt>
jmp    11db <get_cpuinfo_revision+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x824(%rbp)
jne    1295 <get_cpuinfo_revision+0x105>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
jmp    138b <get_cpuinfo_revision+0x1fb>
mov    -0x10(%rbp),%rdi
lea    0xd94(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x830(%rbp)
cmpq   $0x0,-0x830(%rbp)
je     131e <get_cpuinfo_revision+0x18e>
mov    -0x830(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x0,%rax
jne    131e <get_cpuinfo_revision+0x18e>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x5,%eax
jle    131e <get_cpuinfo_revision+0x18e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x840(%rbp),%rsi
mov    -0x838(%rbp),%rdi
sub    $0x4,%eax
cltq
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xd10(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1352 <get_cpuinfo_revision+0x1c2>
mov    -0x10(%rbp),%rdi
lea    0xcfb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    135e <get_cpuinfo_revision+0x1ce>
movl   $0x1,-0x4(%rbp)
jmp    138b <get_cpuinfo_revision+0x1fb>
mov    -0x10(%rbp),%rdi
lea    0xcda(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1384 <get_cpuinfo_revision+0x1f4>
movl   $0x3,-0x4(%rbp)
jmp    138b <get_cpuinfo_revision+0x1fb>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%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,%rbp
lea    0xe55(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     11d7 <get_cpuinfo_revision+0x47>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11f0 <get_cpuinfo_revision+0x60>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %ebx,%ebx
jmp    11dc <get_cpuinfo_revision+0x4c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
lea    0x400(%rsp),%r15
mov    %rsp,%r13
lea    0xe21(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %r15,%rdi
lea    0xde6(%rip),%rsi
mov    %r13,%rdx
call   1090 <sscanf@plt>
mov    %r13,%rdi
lea    0xde2(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%r14d
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1090 <sscanf@plt>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1210 <get_cpuinfo_revision+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14d,%r14d
je     130c <get_cpuinfo_revision+0x17c>
lea    0xdb5(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <strstr@plt>
test   %rax,%rax
je     12b8 <get_cpuinfo_revision+0x128>
cmp    %rbp,%rax
jne    12b8 <get_cpuinfo_revision+0x128>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jl     12b8 <get_cpuinfo_revision+0x128>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%rsi
add    $0xfffffffffffffffc,%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xd7a(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11dc <get_cpuinfo_revision+0x4c>
lea    0xd62(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11dc <get_cpuinfo_revision+0x4c>
lea    0xd4f(%rip),%rsi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
or     $0x2,%ebx
jmp    11dc <get_cpuinfo_revision+0x4c>
xor    %ebx,%ebx
jmp    11dc <get_cpuinfo_revision+0x4c>

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 = [14 x i8] c"Revision\09: %s\00"
@.str.5 = [5 x i8] c"1000\00"
@.str.6 = [5 x i8] c"0002\00"
@.str.7 = [5 x i8] c"0003\00"
@.str.8 = [5 x i8] c"0010\00"
define i32 @get_cpuinfo_revision(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %7
%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 -1, i32* %2
br label %79
12: ; preds = %1
br label %13
13: ; preds = %29, %12
%14 = load i32*, i32** %4
%15 = call i32 @feof(i32* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %33
18: ; preds = %13
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32 @fgets(i8* %19, i32 1024, i32* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %18
store i32 1, i32* %7
br label %29
29: ; preds = %28, %18
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %13
33: ; preds = %13
%34 = load i32*, i32** %4
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %33
store i8* null, i8** %3
store i32 0, i32* %2
br label %79
39: ; preds = %33
%40 = load i8*, i8** %3
%41 = call i8* @strstr(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %41, i8** %8
%42 = load i8*, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %64
44: ; preds = %39
%45 = load i8*, i8** %8
%46 = load i8*, i8** %3
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %44
%52 = load i8*, i8** %3
%53 = call i32 @strlen(i8* %52)
%54 = icmp sgt i32 %53, 5
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i8*, i8** %3
%57 = load i8*, i8** %3
%58 = load i8*, i8** %3
%59 = call i32 @strlen(i8* %58)
%60 = sub nsw i32 %59, 4
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %57, i64 %61
%63 = call i32 @strcpy(i8* %56, i8* %62)
br label %64
64: ; preds = %55, %51, %44, %39
%65 = load i8*, i8** %3
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br i1 %67, label %72, label %68
68: ; preds = %64
%69 = load i8*, i8** %3
%70 = call i64 @strcmp(i8* %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%71 = icmp eq i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %68, %64
store i32 1, i32* %2
br label %79
73: ; preds = %68
%74 = load i8*, i8** %3
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%76 = icmp eq i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %73
store i32 3, i32* %2
br label %79
78: ; preds = %73
store i32 2, i32* %2
br label %79
79: ; preds = %78, %77, %72, %38, %11
%80 = load i32, i32* %2
ret i32 %80
}

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 = [14 x i8] c"Revision\09: %s\00"
@.str.5 = [5 x i8] c"1000\00"
@.str.6 = [5 x i8] c"0002\00"
@.str.7 = [5 x i8] c"0003\00"
@.str.8 = [5 x i8] c"0010\00"
define i32 @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 %50, 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 %50
13: ; preds = %8, %13
%14 = phi i32 [ %19, %13 ], [ 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
%19 = select i1 %18, i32 1, i32 %14
%20 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%21 = call i32 @feof(i32* %6)
%22 = icmp eq i32 %21, 0
br i1 %22, label %13, label %23
23: ; preds = %13
%24 = icmp eq i32 %19, 0
%25 = call i32 @fclose(i32* %6)
br i1 %24, label %50, label %26
26: ; preds = %23
%27 = call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%28 = icmp ne i8* %27, null
%29 = icmp eq i8* %27, %0
%30 = and i1 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %26
%32 = call i32 @strlen(i8* %0)
%33 = icmp sgt i32 %32, 5
br i1 %33, label %34, label %40
34: ; preds = %31
%35 = call i32 @strlen(i8* %0)
%36 = add nsw i32 %35, -4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = call i32 @strcpy(i8* %0, i8* %38)
br label %40
40: ; preds = %34, %31, %26
%41 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %50, label %43
43: ; preds = %40
%44 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
%49 = select i1 %48, i32 3, i32 2
br label %50
50: ; preds = %11, %43, %40, %46, %23, %1
%51 = phi i32 [ -1, %1 ], [ 0, %23 ], [ 1, %43 ], [ 1, %40 ], [ %49, %46 ], [ 0, %11 ]
ret i32 %51
}