#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*/ 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 *, int *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int pi_revision() {
  FILE *fp;
  int revision, match, number;
  char text[128];
  revision = 0;
  fp = fopen("/proc/cpuinfo", "r");
  if (fp) {
    while (fgets(text, 128, fp)) {
      if (!strncmp(text, "Revision", 8)) {
        match = sscanf(text, "%*s : %0X", &number);
        if (match == 1) {
          if (number >= 4)
            revision = 2;
          else
            revision = 1;
        }
        break;
      }
    }
    fclose(fp);
  }
  return revision;
}


x86 assembly (clang, -O0):
<pi_revision>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1222 <pi_revision+0xd2>
jmp    1189 <pi_revision+0x39>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x80,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1219 <pi_revision+0xc9>
lea    -0xa0(%rbp),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1214 <pi_revision+0xc4>
lea    -0xa0(%rbp),%rdi
lea    0xe42(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jne    120f <pi_revision+0xbf>
cmpl   $0x4,-0x14(%rbp)
jl     1203 <pi_revision+0xb3>
movl   $0x2,-0xc(%rbp)
jmp    120a <pi_revision+0xba>
movl   $0x1,-0xc(%rbp)
jmp    120f <pi_revision+0xbf>
jmp    1219 <pi_revision+0xc9>
jmp    1189 <pi_revision+0x39>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0xc(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_revision>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
lea    0xe9c(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ec <pi_revision+0x9c>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
lea    0xe8c(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e2 <pi_revision+0x92>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1190 <pi_revision+0x40>
lea    0xe59(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11e2 <pi_revision+0x92>
xor    %ebp,%ebp
cmpl   $0x4,0xc(%rsp)
setge  %bpl
add    $0x1,%ebp
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11ee <pi_revision+0x9e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
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 = [9 x i8] c"Revision\00"
@.str.3 = [10 x i8] c"%*s : %0X\00"
define i32 @pi_revision() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [128 x i8]
store i32 0, i32* %2
%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** %1
%7 = load i32*, i32** %1
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %35
9: ; preds = %0
br label %10
10: ; preds = %31, %9
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i64 @fgets(i8* %11, i32 128, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%17 = call i32 @strncmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%18 = icmp ne i32 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %15
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%21 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %4)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* %4
%26 = icmp sge i32 %25, 4
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 2, i32* %2
br label %29
28: ; preds = %24
store i32 1, i32* %2
br label %29
29: ; preds = %28, %27
br label %30
30: ; preds = %29, %19
br label %32
31: ; preds = %15
br label %10
32: ; preds = %30, %10
%33 = load i32*, i32** %1
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %0
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"Revision\00"
@.str.3 = [10 x i8] c"%*s : %0X\00"
define i32 @pi_revision() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [128 x i8], [128 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 %23, label %7
7: ; preds = %0, %10
%8 = call i64 @fgets(i8* %4, i32 128, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = call i32 @strncmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %10
%14 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%15 = icmp eq i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 3
%19 = select i1 %18, i32 2, i32 1
br label %20
20: ; preds = %7, %16, %13
%21 = phi i32 [ 0, %13 ], [ %19, %16 ], [ 0, %7 ]
%22 = call i32 @fclose(i32* %5)
br label %23
23: ; preds = %20, %0
%24 = phi i32 [ %21, %20 ], [ 0, %0 ]
ret i32 %24
}