#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*/ str;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, unsigned int *);
unsigned int get_revision_code() {
  FILE *fin;
  char str[256];
  unsigned int revision_num = 0;
  fin = fopen("/proc/cpuinfo", "rt");
  if (fin == NULL)
    return 0;
  while (fgets(str, sizeof(str), fin) != NULL) {
    if (sscanf(str, "Revision : %x", &revision_num) == 1)
      break;
  }
  fclose(fin);
  return revision_num;
}


x86 assembly (clang, -O0):
<get_revision_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x114(%rbp)
lea    0xea4(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <get_revision_code+0x43>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <get_revision_code+0xa6>
jmp    1188 <get_revision_code+0x48>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11d4 <get_revision_code+0x94>
lea    -0x110(%rbp),%rdi
lea    0xe5c(%rip),%rsi
lea    -0x114(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11cf <get_revision_code+0x8f>
jmp    11d4 <get_revision_code+0x94>
jmp    1188 <get_revision_code+0x48>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x114(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_revision_code>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea3(%rip),%rdi
lea    0xeaa(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c6 <get_revision_code+0x86>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
lea    0xe94(%rip),%r15
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b8 <get_revision_code+0x78>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1190 <get_revision_code+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    11c8 <get_revision_code+0x88>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [14 x i8] c"Revision : %x\00"
define i32 @get_revision_code() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i32
store i32 0, i32* %4
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 0, i32* %1
br label %25
9: ; preds = %0
br label %10
10: ; preds = %20, %9
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32* @fgets(i8* %11, i32 256, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %15
br label %21
20: ; preds = %15
br label %10
21: ; preds = %19, %10
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %4
store i32 %24, i32* %1
br label %25
25: ; preds = %21, %8
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [14 x i8] c"Revision : %x\00"
define i32 @get_revision_code() {
%1 = alloca [256 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %0, %10
%8 = call i32* @fgets(i8* %3, i32 256, i32* %5)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = call i32 @sscanf(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %7
13: ; preds = %10, %7
%14 = call i32 @fclose(i32* %5)
%15 = load i32, i32* %2
br label %16
16: ; preds = %0, %13
%17 = phi i32 [ %15, %13 ], [ 0, %0 ]
ret i32 %17
}