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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ isspace(char);
scalar_t__ strncmp(char *, char *, int);
long strtol(char *, int /*<<< orphan*/ *, int);
long iPod_GetGeneration() {
  static long gen = 0;
  if (gen == 0) {
    int i;
    char cpuinfo[256];
    char *ptr;
    FILE *file;
    if ((file = fopen("/proc/cpuinfo", "r")) != NULL) {
      while (fgets(cpuinfo, sizeof(cpuinfo), file) != NULL)
        if (strncmp(cpuinfo, "Revision", 8) == 0)
          break;
      fclose(file);
    }
    for (i = 0; !isspace(cpuinfo[i]); i++)
      ;
    for (; isspace(cpuinfo[i]); i++)
      ;
    ptr = cpuinfo + i + 2;
    gen = strtol(ptr, NULL, 16);
  }
  return gen;
}


x86 assembly (clang, -O0):
<iPod_GetGeneration>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
cmpq   $0x0,0x2ee5(%rip)
jne    12a5 <iPod_GetGeneration+0x145>
lea    0xe80(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
je     11fc <iPod_GetGeneration+0x9c>
jmp    11a2 <iPod_GetGeneration+0x42>
lea    -0x110(%rbp),%rdi
mov    -0x120(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11f0 <iPod_GetGeneration+0x90>
lea    -0x110(%rbp),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11eb <iPod_GetGeneration+0x8b>
jmp    11f0 <iPod_GetGeneration+0x90>
jmp    11a2 <iPod_GetGeneration+0x42>
mov    -0x120(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
movslq -0x4(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%edi
ff
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122a <iPod_GetGeneration+0xca>
jmp    123d <iPod_GetGeneration+0xdd>
jmp    122f <iPod_GetGeneration+0xcf>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1203 <iPod_GetGeneration+0xa3>
jmp    1242 <iPod_GetGeneration+0xe2>
movslq -0x4(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%edi
ff
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     1270 <iPod_GetGeneration+0x110>
jmp    1262 <iPod_GetGeneration+0x102>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1242 <iPod_GetGeneration+0xe2>
lea    -0x110(%rbp),%rax
movslq -0x4(%rbp),%rcx
add    %rcx,%rax
add    $0x2,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %rax,0x2db3(%rip)
mov    0x2dac(%rip),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iPod_GetGeneration>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    0x2ee4(%rip),%rax
test   %rax,%rax
jne    1240 <iPod_GetGeneration+0xe0>
lea    0xe7c(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e2 <iPod_GetGeneration+0x82>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe6e(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11da <iPod_GetGeneration+0x7a>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11b0 <iPod_GetGeneration+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0xffffffff,%ebp
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1050 <isspace@plt>
add    $0x1,%ebp
add    $0x1,%rbx
test   %rax,%rax
je     11f0 <iPod_GetGeneration+0x90>
mov    %ebp,%ebx
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%rsp,%rbx,1),%edi
call   1050 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1210 <iPod_GetGeneration+0xb0>
mov    %ebx,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x2,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <strtol@plt>
mov    %rax,0x2e18(%rip)
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@iPod_GetGeneration.gen = internal global i64 0
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"Revision\00"
define i64 @iPod_GetGeneration() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i8*
%4 = alloca i32*
%5 = load i64, i64* @iPod_GetGeneration.gen
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %58
7: ; preds = %0
%8 = 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* %8, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %25
10: ; preds = %7
br label %11
11: ; preds = %21, %10
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32* @fgets(i8* %12, i32 256, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %22
21: ; preds = %16
br label %11
22: ; preds = %20, %11
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %7
store i32 0, i32* %1
br label %26
26: ; preds = %35, %25
%27 = load i32, i32* %1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = call i64 @isspace(i8 signext %30)
%32 = icmp ne i64 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %38
34: ; preds = %26
br label %35
35: ; preds = %34
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %26
38: ; preds = %26
br label %39
39: ; preds = %47, %38
%40 = load i32, i32* %1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = call i64 @isspace(i8 signext %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %39
br label %47
47: ; preds = %46
%48 = load i32, i32* %1
%49 = add nsw i32 %48, 1
store i32 %49, i32* %1
br label %39
50: ; preds = %39
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%52 = load i32, i32* %1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = getelementptr inbounds i8, i8* %54, i64 2
store i8* %55, i8** %3
%56 = load i8*, i8** %3
%57 = call i64 @strtol(i8* %56, i32* null, i32 16)
store i64 %57, i64* @iPod_GetGeneration.gen
br label %58
58: ; preds = %50, %0
%59 = load i64, i64* @iPod_GetGeneration.gen
ret i64 %59
}

LLVM IR (-O2):
@iPod_GetGeneration.gen = internal unnamed_addr global i64 0
@.str = [14 x i8] c"/proc/cpuinfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"Revision\00"
define i64 @iPod_GetGeneration() {
%1 = alloca [256 x i8]
%2 = load i64, i64* @iPod_GetGeneration.gen
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %38
4: ; preds = %0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, 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 %16, label %8
8: ; preds = %4, %11
%9 = call i32* @fgets(i8* %5, i32 256, i32* %6)
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %8
14: ; preds = %11, %8
%15 = call i32 @fclose(i32* %6)
br label %16
16: ; preds = %14, %4
br label %17
17: ; preds = %16, %17
%18 = phi i64 [ %23, %17 ], [ 0, %16 ]
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @isspace(i8 signext %20)
%22 = icmp eq i64 %21, 0
%23 = add nuw i64 %18, 1
br i1 %22, label %17, label %24
24: ; preds = %17
%25 = and i64 %18, 4294967295
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ %25, %24 ], [ %32, %26 ]
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isspace(i8 signext %29)
%31 = icmp eq i64 %30, 0
%32 = add nuw i64 %27, 1
br i1 %31, label %33, label %26
33: ; preds = %26
%34 = and i64 %27, 4294967295
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 2
%37 = call i64 @strtol(i8* nocapture %36, i32* null, i32 16)
store i64 %37, i64* @iPod_GetGeneration.gen
br label %38
38: ; preds = %33, %0
%39 = phi i64 [ %37, %33 ], [ %2, %0 ]
ret i64 %39
}